Here is the array I'm working with in JavaScript:
let myArray = ["Bob", "Katy", "Bob", "Bob", "Katy"];
I am looking to filter this array by checking if the current value matches the value before or after it. I am a bit unsure on how to approach this, can someone provide guidance?
Currently, I am familiar with using the .filter() method to filter an array based on a specified condition, but I am uncertain about comparing a value with its neighboring values.
Here's what I have so far:
let numberOfBobs = myArray.filter(x => x === "Bob");
However, this does not meet my requirements. I want to count 'Bob' only if there is another 'Bob' immediately before or after it in the array.