Skip to content

Instantly share code, notes, and snippets.

@taterbase
Created November 16, 2012 03:55
Show Gist options
  • Save taterbase/4083889 to your computer and use it in GitHub Desktop.
Save taterbase/4083889 to your computer and use it in GitHub Desktop.
Equilibrium
function equi ( A ) {
var N = A.length;
for(var val in A){
if(check(val, A))
return val;
}
return false
}
function check(index, array){
var fsum = 0;
var lsum = 0;
for(var i = 0; i < index; ++i){
fsum += array[i];
}
for(var i = index + 1; i <= array.length; ++i){
lsum += array[i];
}
if(fsum === lsum)
return true;
else
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment