Created
February 18, 2019 19:28
-
-
Save countaight/31232366ecd6d0159e89702a53f6bc79 to your computer and use it in GitHub Desktop.
Pivot Index Challenge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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