Skip to content

Instantly share code, notes, and snippets.

@adicuco
Created June 15, 2018 17:34
Show Gist options
  • Save adicuco/0e5a6958aaaa21a87511b2f909ccfb5b to your computer and use it in GitHub Desktop.
Save adicuco/0e5a6958aaaa21a87511b2f909ccfb5b to your computer and use it in GitHub Desktop.
100% solution for Tape Equilibrium Task on Codility
function solution(A) {
var min = 99999999999;
var total = 0;
for (var i = 0; i < A.length; i++) {
total += A[i];
}
var sum = 0;
for (var j = 0; j < A.length - 1; j++) {
sum += A[j];
var res = Math.abs(sum - (total - sum));
if (res < min) min = res;
}
return min;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment