Skip to content

Instantly share code, notes, and snippets.

@countaight
Created February 18, 2019 19:28
Show Gist options
  • Select an option

  • Save countaight/31232366ecd6d0159e89702a53f6bc79 to your computer and use it in GitHub Desktop.

Select an option

Save countaight/31232366ecd6d0159e89702a53f6bc79 to your computer and use it in GitHub Desktop.
Pivot Index Challenge
var reduceAry = function(ary) {
return ary.reduce((a, b) => {
return a + b
}, 0);
}
var pivotIndex = function(nums) {
for (var i=0; i < nums.length; i++) {
if (reduceAry(nums.slice(0, i)) === reduceAry(nums.slice(i+1, nums.length))) {
return i;
break;
};
};
return -1;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment