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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -