Last active
January 28, 2020 11:42
-
-
Save laddered/5e2750bffad3ff2afe4c02e874d96d52 to your computer and use it in GitHub Desktop.
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 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