It’s hard to tell the point of this without more context, but if you expand it a bit:
let arr = string
.split(" ")
.map((it) => {
console.log(it);
it = parseInt(it.replace(/[^01]/g, ''), 2);
console.log(it);
return it;
})
.filter(Number);
it may help you see what’s happening. filter() just evaluates its function and returns the array value on truthy, or null otherwise. So if it is parsable as a binary number, then it is not filtered out. If not, map() returns a falsy it, which filter() rejects.
This is speculation, but what I imagine is happening is that you are handing filter the Number constructor which is then being called with the elements of the array, and I would think this is done because the array is filled with strings, and this '0' is a truthy value whereas this 0 is not, and I do not no the context of the problem, but that would indicate that you do not want zeros. You can realistically pass any function for a callback, but I would not have though of writing it the way it was, but for clarity this i the same thing