Last active
September 7, 2015 22:17
-
-
Save morenoh149/6c450ddbafb96d617bee 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
def sorted(a) | |
temp = nil | |
a.each do |e| | |
puts 'temp is: ' + temp.to_s + ' current element is ' + e.to_s | |
if !temp | |
temp = e | |
elsif temp > e | |
return false | |
else | |
temp = e | |
end | |
end | |
puts "returns true" + a.to_s | |
return true | |
end | |
### | |
Example test: [1, 5, 3, 3, 7] | |
Output (stderr): | |
user.rb:24:in `>': comparison of Fixnum with nil failed (ArgumentError) | |
from user.rb:24:in `block in sorted' | |
from user.rb:20:in `each' | |
from user.rb:20:in `sorted' | |
from user.rb:9:in `block in solution' | |
from user.rb:8:in `combination' | |
from user.rb:8:in `each' | |
from user.rb:8:in `solution' | |
from user.rb:141:in `<main>' | |
Output: | |
temp is: current element is 1 | |
temp is: 1 current element is 5 | |
temp is: 5 current element is 3 | |
temp is: current element is 1 | |
temp is: 1 current element is | |
RUNTIME ERROR (tested program terminated unexpectedly) | |
### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment