o9s
is a microblog
home archives search feed blogroll


You learn a little bit every day. This is straightforward except for filter, it does not exist, but you can use select with the logic inverted.

Ruby Map Filter Reduce

map

[1, 2, 3].map { |n| n * n } #=> [1, 4, 9]

filter

[1, 2, 3].select { |n| n != 1 } #=> [2, 3]

reduce

[1, 2, 3].reduce { |memo, n| memo += n } #=> 6
Posted on 2018-04-10   #ruby     #til  






← Next post    ยท    Previous post →