-
-
Save ariejan/537680134081dbe3c468 to your computer and use it in GitHub Desktop.
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
# Print each value in the list as n^2 | |
list = [1, 2, 3, 4, 5, 6, 7] | |
def print_list(list) | |
return if list.empty? | |
n = list.shift # Grabs the first element, removes it from list | |
result = n**2 | |
puts "#{n}^2 = #{result}" | |
print_list(list) | |
end | |
print_list(list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment