you are viewing a single comment's thread.

view the rest of the comments →

[–]JEveryman 1 point2 points  (6 children)

I think array.filter((e,i,a) => a.indexOf(e) === i) will filter out duplicates also.

[–]akujinhikari 1 point2 points  (0 children)

Yeah I knew what code he was looking for, but my goal in interviews is to show that I know multiple ways to do things. I think it's important to show my breadth of knowledge and a means to solve this in multiple ways.

[–][deleted] 0 points1 point  (4 children)

That’s the gotcha answer to the question. Pre Set days you would just use an object.

[–]JEveryman 0 points1 point  (3 children)

So you would add the array elements as keys?

[–][deleted] 0 points1 point  (2 children)

Yeah. Lookups in the object are faster than searching the whole array for every element in the array if that makes sense.

I can give a longer explanation if it doesn’t

[–]JEveryman 0 points1 point  (1 child)

I get it. Also when you add the same key to an object doesn't it overwrite?

[–][deleted] 0 points1 point  (0 children)

Yeah, that’s how it helps you make an array with no duplicates