My guess is that you do not know what is stored in unsorted . From the error message it looks like it is an array of arrays while you are expecting it to be a simple array of values. It is difficult to tell for sure without understanding the calling context.
L7Sqr
Practically a Posting Shark
849 posts since Feb 2011
Reputation Points: 253
Solved Threads: 155
Skill Endorsements: 7
You are still getting an undefined method error on an array - that is exactly what NoMethodError means. Consider the following:
#!/usr/bin/env ruby
if [1,2,3,4,5] < [4,5,6,7,8,9]
puts "Less than"
end
Running that gives me the following exception
undefined method `<' for [1, 2, 3, 4, 5]:Array (NoMethodError)
Look familiar?
You are not getting what you expect in that function.
L7Sqr
Practically a Posting Shark
849 posts since Feb 2011
Reputation Points: 253
Solved Threads: 155
Skill Endorsements: 7
At some point you are accessing beyond the stored elements in your array. var likely becomes unsorted.size and you then use it as an index into unsorted causing a nil result.
L7Sqr
Practically a Posting Shark
849 posts since Feb 2011
Reputation Points: 253
Solved Threads: 155
Skill Endorsements: 7
I've always found that working through tough problems made me a better programmer. We all face problems when starting out that challenge us; as you progress in you abilities you start to look for these situations to break up the monotony. At least that is the way it has happened for me.
L7Sqr
Practically a Posting Shark
849 posts since Feb 2011
Reputation Points: 253
Solved Threads: 155
Skill Endorsements: 7
Question Answered as of 1 Year Ago by
L7Sqr