I have an array and i would like to find all neighboring matches and count them, then return the count, performed in a loop like .map() so it wont be necessary to store a memory of what was counted beyond the current element. i need to use this number of current elements to reserve enough spaces for each group of elements
array = [ball, batter, batter, amount, amount, github, github, github, account, account, account, account, account, account, account, github, github, github]
example of desired results from this array would be: on first loop would return 1, second loop would return 2, then 2, then 3, then 7, then 3
and this count would be used as a variable to reserve space, something like
number to reserve: count
so through each loop, the variable count
would be changed and updated to the current elements count, and the loop that counts would not stop until the next element is not a match for the current element, and the variable count
will also not be available for use until all concurrent matches are found, so if i put console.log(count)
at the end of the function i would get each number output individually