You are overruning the bounds of your array. The example you were given was assuming 1-indexed arrays, but arrays in ruby are 0-indexed. The first line should be
for j in 1...num.length
More Related Contents:
- What’s the best way to model recurring events in a calendar application? [closed]
- Sort an array according to the elements of another array
- All factors of a given number
- How to convert Time format in ruby
- Why do Ruby setters need “self.” qualification within the class?
- What is the difference between require_relative and require in Ruby?
- Why does Ruby 1.9.2 remove “.” from LOAD_PATH, and what’s the alternative?
- rvm installation not working: “RVM is not a function”
- Ruby array access 2 consecutive(chained) elements at a time
- What does %w(array) mean?
- What does &. (ampersand dot) mean in Ruby?
- How to get argument names using reflection
- How to count duplicate elements in a Ruby array
- When to use `self.foo` instead of `foo` in Ruby methods
- Should Gemfile.lock be included in .gitignore?
- Is the ruby operator ||= intelligent?
- Unresolved specs during Gem::Specification.reset:
- Ruby 1.9: how can I properly upcase & downcase multibyte strings?
- How can I clear the terminal in Ruby?
- Ruby ‘require’ error: cannot load such file
- Testing modules in RSpec
- Why do two strings separated by space concatenate in Ruby?
- When do Ruby instance variables get set?
- Is order of a Ruby hash literal guaranteed?
- RVM and thin, root vs. local user
- Ruby array subtraction without removing items more than once
- Where is it legal to use ruby splat operator?
- Net::ReadTimeout (Net::ReadTimeout) Selenium Ruby
- Rails ‘parse_query’ error on server in brand new app
- How do I remove blank elements from an array?