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; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter