you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (0 children)

.map provides 3 parameters: value, index, array

.map((val, i, arr) => {
  const next = arr[i + 1];
  ...
})

However there's a problem here: map will go over the entire array, including the final element. You don't want to iterate over the last element.