Skip to content

Instantly share code, notes, and snippets.

@Ebonkuab
Created January 6, 2016 20:58
Show Gist options
  • Save Ebonkuab/ce388f952e831cd43ea4 to your computer and use it in GitHub Desktop.
Save Ebonkuab/ce388f952e831cd43ea4 to your computer and use it in GitHub Desktop.
code decoded during the debugging excercise in Lighthouse Labs
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