help me js code

1 Like

This logic you used will just compare two adjacent names. Not check if a name at a particular position is there or not in the entire remaining array.

For example, if you have [“Peter”, “David”, “Robert”, “David”, “Jared”], then this would just check David and Robert on the second iteration and push David. Then push Robert on the third iteration. But then again check David and Jared on the fourth iteration and push David once again.

One way would be to check if names[i] is absent in your new array nam and then only push. Or else don’t.

It is just a linear search through the array to check if each element is already pushed to the new array or not. So the complexity would be of the order of N for N elements of the array. Coz at each iteration we are dealing with the N elementa of the array.
But no need to worry about the complexity. Since you say you are super new, right now it just important to think through the problem like a programmer. Optimal solutions and efficiency will come with practice .

1 Like

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

Noted @JeremyLT I got carried away there.