Skip to content

Instantly share code, notes, and snippets.

@laddered
Last active January 28, 2020 11:42
Show Gist options
  • Save laddered/5e2750bffad3ff2afe4c02e874d96d52 to your computer and use it in GitHub Desktop.
Save laddered/5e2750bffad3ff2afe4c02e874d96d52 to your computer and use it in GitHub Desktop.
function solution(A) {
let P=A.length-1, difArr=[]
for(let i=1; i<=P; i++){
let LSumm=0, RSumm=0;
for(let j=0; j<A.length; j++){
if(j<i){
LSumm+=A[j]
}
else{
RSumm+=A[j]
}
}
let dif=LSumm-RSumm
if (dif<0){dif=-dif}
difArr.push(dif)
}
difArr.sort((a, b) => a > b ? 1 : -1);
return difArr.shift()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment