I'm using this piece of code to compare the summation of left side and compare it to the summation of right side, the sum method uses list.reduce function to compute the sum.
My question is: I expect this piece of code not to work, since the for loop will iterate to the next iteration without waiting for the async sum function!!
How is that possible?
for(var i of pivot){
var left = arr.slice(0,i)
var right = arr.slice(i+1)
console.log('left: ',left)
console.log('right: ',right)
if( sum(left) == sum(right) ){
console.log('equilibrium point: ' + i)
}
}
via securecurve
No comments:
Post a Comment