Created
November 16, 2012 03:55
-
-
Save taterbase/4083889 to your computer and use it in GitHub Desktop.
Equilibrium
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
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