I am trying to solve a problem related to javascript algorithms. Here's the problem. I want to access the index of an array value by indexOf() method. But I want to know how can I avoid the same index when most values in the array are the same. Take example:
let arr1 = [0, 0, 0, 0, 1, 1];
Now as you can see most of the values are same and indexOf method looks for an index of a given value in the array.
arr1.indexOf(arr1[0]); // 0
arr1.indexOf(arr1[5]); // 5
So, it will return 0 as the system but when I will going to move further to access the next value. Like:
arr1.indexOf(arr1[1]); // 0
arr1.indexOf(arr1[6]); // 5
It returns the same as before. But I want the next index instead of same. Ex:
arr1.indexOf(arr1[1]); // 1
It should return 1 because 0 is already returned one time. So, what is the solution to this?