Skip to content

Instantly share code, notes, and snippets.

@SophieDeBenedetto
Created July 1, 2015 18:56
Show Gist options
  • Save SophieDeBenedetto/c2cf59b57a4aa5be6d9a to your computer and use it in GitHub Desktop.
Save SophieDeBenedetto/c2cf59b57a4aa5be6d9a to your computer and use it in GitHub Desktop.
multiple repls
# Enumerator Coding Challenge
## Ojbectives
Become familiar using common iterators introduced in the previous lesson.
%%%
### Code Challenge I: Using `.each`
Let's try out the enumerator methods we just learned. Refer back to the previous lesson to help you pass this challenge.
Below, we have a variable, `lunch_menu`, set equal to an array of lunch menu items. Use the `.each` method to enumerate over the array and puts out each menu item.
```ruby
lunch_menu = ["pizza", "sandwhich", "sushi", "soup", "salad"]
#code your solution using .each here
~~~solution
lunch_menu.each do |lunch_item|
puts lunch_item
end
~~~validation
correct = "pizza\nsandwhich\nsushi\nsoup\nsalad"
assert.strictEqual(response, correct);
```
%%%
%%%
### Code Challenge II: Using `.collect`
Below we have a variable, `nums`, set equal to an array of numbers. Enumerate over the array with the `.collect` method and return a new array of the same numbers, squared.
```ruby
nums = [1, 2, 3, 4]
#code you solution using .collect here
~~~solution
nums.collect do |num|
num * num
end
~~~validation
answer = [2, 4, 9, 16]
assert.strictEqual(response, answer);
```
%%%
my question: wondering if this is the right way to include multiple repls in one readme? I separated them out into their own %%% … %%% blocks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment