I have an array with a size of 5 and in each element, I fill in with a corresponding subarray, like this:
let equalSums = new Array(5);
for (let i = 0; i < equalSums.length; i++) {
equalSums[i] = new Array(5);
}
console.log(equalSums);
/*
[ [ , , , , ],
[ , , , , ],
[ , , , , ],
[ , , , , ],
[ , , , , ] ]
*/
And after malnipulating to find contigous subarray that equal to a give number (in this case it's 3), I push subarray with sum elements equal 3 to this equalSum
array, and now it looks like this:
[ [ , , , , ],
[ , , , , ],
[ , , , , ],
[ , , , , ],
[ , , , , ],
[ 1, 2 ],
[ 2, 1 ],
[ 3 ] ]
The problem is I want to remove all the empty subarrays, then I do the following:
let rs = equalSums.filter(e => e.every(x => x != ""));
console.log(rs);
/*
[ [ , , , , ],
[ , , , , ],
[ , , , , ],
[ , , , , ],
[ , , , , ],
[ 1, 2 ],
[ 2, 1 ],
[ 3 ] ]
/*
Still the same, it doesn't remove the empty subarrays.
But, I use some
instead, it gives me the desired result:
let rs = equalSums.filter(e => e.some(x => x != ""));
console.log(rs);
/*
[ [ 1, 2 ], [ 2, 1 ], [ 3 ] ]
*/
Can anybody explain for me why every
doesn't work and some
does?