session3/challenge/2_hashes.rb
# Given a nonnegative integer, return a hash whose keys are all the odd nonnegative integers up to it
# and each key's value is an array containing all the even non negative integers up to it.
#
# Examples:
# staircase 1  # => {1 => []}
# staircase 2  # => {1 => []}
# staircase 3  # => {1 => [], 3 => [2]}
# staircase 4  # => {1 => [], 3 => [2]}
# staircase 5  # => {1 => [], 3 => [2], 5 =>[2, 4]}
Given a nonnegative integer, return a hash whose keys are all the odd nonnegative integers up to it
and each key's value is an array containing all the even non negative integers up to it.


Given a nonnegative integer return a hash whose keys are all the odd nonnegative integers up to it and each key ' s value is an array containing all the even non negative integers up to it .
def staircase(n)
  hash = {}
  keys = [*1..n].select { |n| n.odd? }
  keys.each { |key| hash[key] = [*1..key].select { |n| n.even? } }
  hash
end
def staircase ( n ) hash = { } keys = [ * 1 .. n ] . select { | n | n . odd? } keys . each { | key | hash [ key ] = [ * 1 .. key ] . select { | n | n . even? } } hash end
Given a nonnegative integer, return a hash whose keys are all the odd nonnegative integers up to it
and each key's value is an array containing all the even non negative integers up to it.
Given a nonnegative integer return a hash whose keys are all the odd nonnegative integers up to it and each key ' s value is an array containing all the even non negative integers up to it .
n
<not_specific>