Skip to content

Instantly share code, notes, and snippets.

@layonthebeech
Created August 18, 2016 14:38
Show Gist options
  • Save layonthebeech/e87c4adcc4fd651b9dd4e2d2156764de to your computer and use it in GitHub Desktop.
Save layonthebeech/e87c4adcc4fd651b9dd4e2d2156764de to your computer and use it in GitHub Desktop.
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