Find equal sides of an array with splice and reduce

PHOTO EMBED

Thu Sep 28 2023 14:11:11 GMT+0000 (Coordinated Universal Time)

Saved by @Paloma

function findEvenIndex(arr) {
  let index = -1;
  for (var i = 0; i < arr.length; i++) {
    let start = arr.slice(0, i+1).reduce((a, b) => a + b, 0);
    let end = arr.slice(i).reduce((a, b) => a + b, 0)
    if (start === end) {
      index = i
    }
  }
  return index;
}
content_copyCOPY

https://stackoverflow.com/questions/71543463/equal-sides-of-an-array-in-js