Skip to content

Instantly share code, notes, and snippets.

@morenoh149
Last active September 7, 2015 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morenoh149/6c450ddbafb96d617bee to your computer and use it in GitHub Desktop.
Save morenoh149/6c450ddbafb96d617bee to your computer and use it in GitHub Desktop.
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