I need to find the maximum slice of an array that contains no more than two different numbers.
Here is my array [1, 1, 1, 2, 2, 2, 1, 1, 2, 2, 6, 2, 1, 8]
My thought process is to find numbers that don't repeat and return their index to a new array.
Here is what I still have:
function goThroughInteger(number) { var array = []; //iterate the array and check if number is not repeated number.filter(function (element, index, number) { if(element != number[index-1] && element != number[index+1]) { array.push(index); return element; } }) console.log(array); } goThroughInteger([1, 1, 1, 2, 2, 2, 1, 1, 2, 2, 6, 2, 1, 8]);
I'm not sure where to go next, I struggle to understand the question of what it is - to find the maximum cut that contains no more than two different numbers - it bothers me.