functional programming - A "map" to only part of the elements in Javascript -
is there way, in javascript (es2015), map part of array?
e.g.:
let m = somearray.map(function(n){ if(n===0) return n+1; }
that's it, return mapped array has less elements original one.
is accomplish out of box functional programming technique?
maps changing number of elements icky. it's better filter first, map:
let arr2 = arr.filter(e => e === 0).map(e => e + 1);
Comments
Post a Comment