Skip to content

Commit bea52ec

Browse files
authored
Merge pull request #109 from SeanRParker/ruby_sort_reverse
Add reverse and sort methods for Ruby
2 parents 42a0613 + 869742a commit bea52ec

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ _Sorting algorithms implemented in different languages (for hacktoberfest_ 😃_
1212
| Java | [`Bead Sort`](Java/BeadSort.java) [`Bogo Sort`](Java/BogoSort.java) [`Bubble Sort`](Java/BubbleSort.java) <br> [`Counting Sort`](Java/Counting%20Sort.java) [`Heap Sort`](Java/HeapSort.java) [`Insertion Sort`](Java/InsertionSort.java) <br> [`Merge Sort`](Java/MergeSort.java) [`Quick Sort`](Java/QuickSort.java) [`Radix Sort`](Java/RadixSort.java) <br> [`Selection Sort`](Java/SelectionSort.java) [`Shell Sort`](Java/ShellSort.java) [`Tim Sort`](Java/TimSort.java) <br> [`Comb Sort`](Java/CombSort.java) [`Binary Insertion Sort`](Java/BinaryInsertionSort.java) [`Gnome Sort`](Java/GnomeSort.java) |
1313
| Javascript | [`Bogo Sort`](Javascript/bogoSort.js) [`Counting Sort`](Javascript/countingSort.js) [`Heap Sort`](Javascript/HeapSort.js) [`Insertion Sort`](Javascript/Insertionsort.js) [`Merge Sort`](Javascript/MergeSort.js) <br> [`Quick Sort`](Javascript/Quicksort.js) [`Bubble Sort`](Javascript/bubbleSort.js) [`Shell Sort`](Javascript/shellSort.js ) [`Selection Sort`](Javascript/selectionSort.js) <br> [`Radix Sort`](Javascript/RadixSort.js) |
1414
| Python | [`Bogo Sort`](Python/BogoSort.py) [`Bubble Sort`](Python/BubbleSort.py) [`Bucket Sort`](Python/BucketSort.py) <br> [`Gnome Sort`](Python/GnomeSort.py) [`Insertion Sort`](Python/InsertionSort.py) [`Merge Sort`](Python/MergeSort.py) <br> [`Quick Sort`](Python/QuickSort.py) [`Radix Sort`](Python/RadixSort.py) [`Selection Sort`](Python/SelectionSort.py) <br> [`Binary Insertion Sort`](Python/BinaryInsertionSort.py) [`Heap Sort`](Python/heapSort.py) |
15-
| Ruby | [`Bubble Sort`](Ruby/bubble_sort.rb) [`Gnome Sort`](Ruby/gnome_sort.rb)
15+
| Ruby | [`Bubble Sort`](Ruby/bubble_sort.rb) [`Gnome Sort`](Ruby/gnome_sort.rb) [`Sort`](Ruby/sort.rb) [`Reverse sort`](Ruby/reverse.rb)
1616
| Kotlin |[`Merge Sort`](Kotlin/MergeSort.kt) [`Bubble Sort`](Kotlin/BubbleSort.kt) [`Selection Sort`](Kotlin/selectionSort.kt) <br> [`Heap Sort`](Kotlin/HeapSort.kt) [`Insertion Sort`](Kotlin/InsertionSort.kt) [`Quick Sort`](Kotlin/QuickSort.kt) [`Bogo Sort`](Kotlin/BogoSort.kt)
1717
| Elixir | [`Selection Sort`](Elixir/selectionSort.exs)
1818

Ruby/reverse.rb

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
letters = ["b", "d", "e", "a", "c"]
2+
=> ["b", "d", "e", "a", "c"]
3+
# Ruby doesn't care about the alphabetical pattern, it only reverses the order of the array
4+
letters.reverse
5+
=> ["c", "a", "e", "d", "b"]
6+
# The original array wasn't mutated because bang(!) wasn't used.
7+
letters
8+
=> ["b", "d", "e", "a", "c"]
9+
10+
# Using bang(!) here mutates the array so the order has changes
11+
letters.reverse!
12+
=> ["c", "a", "e", "d", "b"]
13+
letters
14+
=> ["c", "a", "e", "d", "b"]

Ruby/sort.rb

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
letters = [b, d, e, a, c]
2+
letters.sort
3+
=> ["a", "b", "c", "d", "e"]
4+
5+
# checking letters again shows the original array
6+
letters
7+
=> ["b", "d", "e", "a", "c"]
8+
9+
letters.sort!
10+
=> ["a", "b", "c", "d", "e"]
11+
letters
12+
=> ["a", "b", "c", "d", "e"]
13+
14+
# using .sort! (with the exclamation mark) mutates your original letters array.

0 commit comments

Comments
 (0)