DEV Community

Discussion on: Comparing elements in an Array and eliminating duplicates

Collapse
t0maslb profile image
t0maslb • Edited on

This is how I'd do it in Python:

def delete_dupl(list):
    deleted = {}
    # add each element to a map
    for item in list:
        deleted[item] = 1
    # clear list to replace with the shortened one
    list.clear()
    for key in deleted:
        list.append(key)
    return deleted
print(delete_dupl(<given_list>))

There's probably a better way but adding each item to a map (dict) is enough, as there can't be repeated keys; then pass every key to an array.

Collapse
ezeugoobieze profile image
mr.Felistus Author

Ok..
I don't speak python for now. Am a newbie in JavaScript trying to work on that task.

Thanks for your response...👍

Collapse
t0maslb profile image
t0maslb

Well, I'm not fluent on JS either but I don't think they're so different at tackling this problem :)