why got it this result in array.filter? javascript | SoloLearn: Learn to code for FREE!

0

why got it this result in array.filter? javascript

JAVASCRIPT var c = new Array(1, 2, 3, 4, 5, 6); var b = c.filter(function(a) { return (a % 2) - 1; }); //output [2,4,6] i dont understand it

3/16/2020 5:40:14 PM

MetaCop

3 Answers

New Answer

+3

The lambda function secretly returns a boolean. So in any case if (a%2)-1 I.e 1-1 for even numbers.. which is Zero or false. Should be filtered. So the even numbers got filtered

+2

xaralampis_ Why you are going on profile pic?

0

Pip?