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
| def fizzbuzz(startnumber,endnumber) | |
| #check input for Fixnum | |
| if !(startnumber.is_a?(Fixnum) && endnumber.is_a?(Fixnum)) | |
| puts "invalid input" | |
| return nil | |
| end | |
| #check start number is smaller than end number | |
| if startnumber > endnumber | |
| puts "Start number #{startnumber} is greater than end number #{endnumber}, reverting the loop" |
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
| # Find the maximum | |
| def maximum(arr) | |
| arr.inject(arr[0]) do |sum,a| | |
| a > sum ? a : sum | |
| end | |
| end | |
| # expect it to return 42 below | |
| result = maximum([2, 42, 22, 02]) | |
| puts "max of 2, 42, 22, 02 is: #{result}" |
NewerOlder