Skip to content

Instantly share code, notes, and snippets.

@SanSan-
Created August 1, 2016 13:25
Show Gist options
  • Save SanSan-/b6ed9f4a0b061a7748075833390b13c7 to your computer and use it in GitHub Desktop.
Save SanSan-/b6ed9f4a0b061a7748075833390b13c7 to your computer and use it in GitHub Desktop.
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