Skip to main content
added 179 characters in body; edited body; deleted 45 characters in body
Source Link
Caridorc
  • 28.2k
  • 7
  • 55
  • 138

while with manual incrementing should be avoided at all costs in Ruby, the following reads much more easily:

interrupt.times do
    for x in 1..arr.length-1
        if arr[x-1] > arr[x]
            arr[x-1], arr[x] = arr[x], arr[x-1]
        end
    end
end

You can simplify this line:

line.map!(&:to_i)

As ! Makes methods work in place. &: converts a method to a block.


(minor) remove that semicolon, it is really weird:

line = line.chomp.split(" ");

while with manual incrementing should be avoided at all costs in Ruby, the following reads much more easily:

interrupt.times do
    for x in 1..arr.length-1
        if arr[x-1] > arr[x]
            arr[x-1], arr[x] = arr[x], arr[x-1]
        end
    end
end

(minor) remove that semicolon, it is really weird:

line = line.chomp.split(" ");

while with manual incrementing should be avoided at all costs in Ruby, the following reads much more easily:

interrupt.times do
    for x in 1..arr.length-1
        if arr[x-1] > arr[x]
            arr[x-1], arr[x] = arr[x], arr[x-1]
        end
    end
end

You can simplify this line:

line.map!(&:to_i)

As ! Makes methods work in place. &: converts a method to a block.


(minor) remove that semicolon, it is really weird:

line = line.chomp.split(" ");
Source Link
Caridorc
  • 28.2k
  • 7
  • 55
  • 138

while with manual incrementing should be avoided at all costs in Ruby, the following reads much more easily:

interrupt.times do
    for x in 1..arr.length-1
        if arr[x-1] > arr[x]
            arr[x-1], arr[x] = arr[x], arr[x-1]
        end
    end
end

(minor) remove that semicolon, it is really weird:

line = line.chomp.split(" ");