Find the Middle Index in Array LeetCode solution in JavaScript

1
var findMiddleIndex = function (nums) {
2
for (let i = 0; i < nums.length; i++) {
3
let leftNums = nums.slice(0, i).reduce((a, b) => a + b, 0);
4
let rightNums = nums.slice(i + 1).reduce((a, b) => a + b, 0);
5
if (leftNums === rightNums) {
6
return i;
7
}
8
}
9
return -1;
10
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0