In an array of numbers, I need to find repeating values and replace them with null.
Examples
Replace 6 in the middle of array if its neighbors are also 6
[1, 4, 3, 6, 6, 6, 6, 3, 2] => [1, 4, 3, 6, null, null, 6, 3, 2]
Replace 6 at the end of the array if the penultimate value is 6 :
[2, 6, 6, 6, 5, 2, 6, 6] => [2, 6, null, 6, 5, 2, 6, null]
Replace 6 at the start of the array if the next value is 6
[6, 6, 2, 3, 5, 6] => [null, 6, 2, 3, 5, 6]
Any ideas how to achieve this? I’m open to using lodash / underscore if needed