- select
- select
Select - keep certain key-value pairs
examples/hashes/select.cr
planets = { "Mars" => 1, "Jupyter" => 2, "Saturn" => 3, "Earth" => 4, } puts planets.select { |name, number| number > 2 && name.includes?("r") } puts planets puts planets.select! { |name, number| number > 2 && name.includes?("r") } puts planets
{"Saturn" => 3, "Earth" => 4} {"Mars" => 1, "Jupyter" => 2, "Saturn" => 3, "Earth" => 4} {"Saturn" => 3, "Earth" => 4} {"Saturn" => 3, "Earth" => 4}