I achieved this using the while loop and the splice method for JavaScript arrays.
I stored the index of the first and second elements in the array in the variables, current
and next
respectively. I looped through the array at every element, checked if the current element is equal to the next element. If this returns true, I use the splice method to remove that element. On the other hand, if it returns false, I set the current
variable to the next index and subsequent the next
variable.
At the end of the loop, I return the length of the array.
Top comments (0)