Last active
January 4, 2016 20:44
-
-
Save HintikkaKimmo/6de1dcdd8df92b73dda7 to your computer and use it in GitHub Desktop.
Lesson 2 solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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