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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

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

android - How to create dynamically Fragment pager adapter -