Python's
prev = [1,2,3,4]
next = [x * 2 for x in old]
Is the same as javascript's prev = [1,2,3,4];
next = prev.map(x => x * 2);
Python's next = [x for x in prev if x % 2 == 0]
is the same as javascript's next = prev.filter(x => x % 2 === 0);
And finally, python's next = [x * 2 for x in prev if x % 2 == 0]
is the same as next = prev.filter(x => x % 2 == 0).map(x => x * 2);
It could be nice to have a "mapIf" function that accepts a mapping and a predicate, but I think the extra verbosity makes the above code easier to understand. next = prev.mapIf(x => x * 2, x => x % 2 == 0);