Created
February 21, 2016 18:56
-
-
Save lovasoa/2f0f6e80d8fb14e8cff7 to your computer and use it in GitHub Desktop.
mapfilter function, just like map, but can also discard elements. Equivalent to array.map(fun).filter(n => n !== undefined)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mapfilter(array, fun) { | |
// Equivalent to array.map(fun).filter(x => x !== undefined) | |
var res = []; | |
for(var i=0; i<array.length; i++) { | |
var r = fun(array[i], i, array); | |
if (r !== void 0) res.push(r); | |
} | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Exemple use :