Skip to content

Instantly share code, notes, and snippets.

@HintikkaKimmo
Last active January 4, 2016 20:44
Show Gist options
  • Save HintikkaKimmo/6de1dcdd8df92b73dda7 to your computer and use it in GitHub Desktop.
Save HintikkaKimmo/6de1dcdd8df92b73dda7 to your computer and use it in GitHub Desktop.
Lesson 2 solution
# Grab 23 random elements between 0 and 10000
arr = (1..10000).to_a.sample(23)
p arr
# This selects only elements that when divided by 3 have a remainder of 0
# using the % (modulus) operator
p arr.select { |element| element % 3 == 0 }
# Using `reject` method filter out anything less than 5000
# and use `sort` and `reverse` methods to sort in descending order
# Start with the line below and continue as 1 long method chain
p arr.select { |element| element % 3 == 0 }.reject { |element| element <= 5000 }.sort.reverse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment