Created
August 1, 2016 13:25
-
-
Save SanSan-/b6ed9f4a0b061a7748075833390b13c7 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 solution(A) { | |
function rightSum(A, N, i, res) { | |
i = typeof i !== 'undefined' ? i : 0; | |
res = typeof res!== 'undefined' ? res : 0; | |
if (i>=N) { | |
return res; | |
} else { | |
return rightSum (A, N, i+1, res+A[i]); | |
} | |
} | |
function leftSum(A, N, res) { | |
res = typeof res!== 'undefined' ? res : 0; | |
if (N<A.length) { | |
return leftSum(A, N+1, res+A[N]); | |
} else { | |
return res; | |
} | |
} | |
function loop(A, N, res) { | |
if (N>=A.length) { | |
return res; | |
} else if (rightSum(A, N)===leftSum(A, N+1)) { | |
return N; | |
} else { | |
return loop(A, N+1, res); | |
} | |
} | |
return loop(A, 0, -1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment