Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
even_numbers = [1, 2, 3, 4, 5].map { |element| element if element.even? } # [ni, 2, nil, 4, nil]
even_numbers = even_numbers.compact # [2, 4]
@willhaslett

This comment has been minimized.

Copy link

willhaslett commented Dec 25, 2017

in Rust ... You don't need a compact.

Same in Ruby. Instead of map and compact, you would use select here.

Thanks for the post on Rust! As a Rubyist, makes it seem less daunting.

@nicoder

This comment has been minimized.

Copy link

nicoder commented Jan 7, 2018

s/ni/nil ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.