Created
August 18, 2016 14:38
-
-
Save layonthebeech/e87c4adcc4fd651b9dd4e2d2156764de to your computer and use it in GitHub Desktop.
This file contains 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
function findEvenIndex(arr) | |
{ | |
var left = 0, right = arr.reduce(function(pv, cv) { return pv + cv; }, 0); | |
for(var i = 0; i < arr.length; i++) { | |
if(i > 0) left += arr[i-1]; | |
right -= arr[i]; | |
if(left == right) return i; | |
} | |
return -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment