Reputation: 473
What operation is being done to the arr[i], arr[i+1]
in the second line:
if arr[i] > arr[i + 1]
arr[i], arr[i + 1] = arr[i + 1], arr[i]
sorted = false
end
Upvotes: 1
Views: 70
Reputation: 118261
What operation is being done to the arr[i], arr[i+1] in the second line.
arr[i], arr[i + 1] = arr[i + 1], arr[i]
means value swapping to sort the array.
arr = [3,2]
i = 0
arr[i], arr[i + 1] = arr[i + 1], arr[i]
arr # => [2,3]
What's this type of ternary called?
This is called parallel
assignment,not ternary.
Upvotes: 4