Arrays: Left Rotation

  • + 10 comments

    hmm.. I'm surprised that worked for you. This one worked for me:

    str = ''
    
    length_of_array.times do |i|
      new_index = (i + no_of_left_rotation) % length_of_array
      str += "#{array[new_index]} "
    end
    
    puts str.strip