سؤال

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