From 3e175e52b3643f3e685c5ac75ccd63b46399b58d Mon Sep 17 00:00:00 2001 From: chrisgithubok <36055072+chrisgithubok@users.noreply.github.com> Date: Thu, 27 Jun 2019 13:20:31 -0700 Subject: [PATCH] added ruby bubble_sort example (#33907) * added ruby bubble_sort example * fix: corrected code block syntax * fix: fixed typo and used 2 space indentation --- .../sorting-algorithms/bubble-sort/index.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/guide/english/algorithms/sorting-algorithms/bubble-sort/index.md b/guide/english/algorithms/sorting-algorithms/bubble-sort/index.md index 1419344d51..4baaf677d9 100644 --- a/guide/english/algorithms/sorting-algorithms/bubble-sort/index.md +++ b/guide/english/algorithms/sorting-algorithms/bubble-sort/index.md @@ -51,7 +51,6 @@ Now, the array is already sorted, but our algorithm does not know if it is compl ### Video Explanation [Bubble sort in easy way](https://www.youtube.com/watch?v=Jdtq5uKz-w4) ------ ### Example in JavaScript ```js @@ -159,6 +158,22 @@ def bubbleSort(arr): ``` +### Example in Ruby +```ruby +def bubble_sort(arr) + sorted = false + until sorted + sorted = true + (arr.count-1).times do|i| + if arr[i] > arr[i + 1] + arr[i], arr[i +1] = arr[i +1], arr[i] + sorted = false + end + end + end +arr end +``` + ### Example in PHP ```php