Created
January 6, 2016 20:58
-
-
Save Ebonkuab/ce388f952e831cd43ea4 to your computer and use it in GitHub Desktop.
code decoded during the debugging excercise in Lighthouse Labs
This file contains 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
def sum(list) | |
sum = 0 | |
list.each do |num| | |
sum += num | |
end | |
sum | |
end | |
list1 = [16,21,31,42,55] | |
# 1. The following should return 165 instead of an error | |
puts sum(list1) | |
# 2. How would you refactor it using an enumerable method other than each? Examples of enumerables: map, select, inject, reject, detect. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment