문제

I have an array with some values:

[1, 2, 3, 4]

I'd like to make a new array that contains mapped version of the items in the array above, but only add them to the new array if they pass a truth test.

A combination of map and filter?

[1, 2, 3, 4].mapFilter(function(n) { if (n > 2) return n * 3 })

What is this called?

도움이 되었습니까?

해결책

This is map composed with filter. It doesn't need a name.

map (*3) . filter (>2)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top