A demonstration of bubble-sort method which sorts in ascending mode the elements of a collection using Ruby language. This is a project of the Microverse Ruby Course.
This project is part of the Microverse curriculum in Ruby module!
Explore the docs »
View Demo
Report Bug
Request Feature
The project consists of three code files
-
bubble_sort.rb Contains the method bubble_sort. The bubble_sort methods accepts either an array of numbers and sorts them according to their value in ascending order or an array of strings and sorts them in ascending order alphabetically. An error occurs if the method is passed an array with mixed numbers and strings.
-
bubble_sort_by.rb Contains the method bubble_sort_by. The bubble_sort_by method accepts an array of strings and sorts them according to their size (length) in ascending order. Also, it uses a block to manage the sorting procedure which is called-back by a yield statement inside the method. An error occurs if the method is passed an array of numbers.
-
test.rb Contains test code for the two methods.
You may test the code either by running the test.rb file using Ruby or provide your own array such as
- for bubble_sort [10, 9, 5, 2, 3, 4] or [5.45, 3.1, 3, 2, 1]
- for bubble_sort_by ['avalon', 'beta', 'con'] Please note, the method bubble_sort_by requires a block of the form {|x, y| x <=> y}.
This project was built using these technologies.
- Ruby
- Rubocop
- VsCode
👤 Author_1 ## Adetayo Sunkanmi
- Github: @jstloyal
- Twitter: @jstloyalty
- Linkedin: Adetayo Sunkanmi
- E-mail: jstloyalty@gmail.com
👤 Author_2 ## Ioannis Kousis
- Github: @ioanniskousis
- Twitter: @ioanniskousis
- Linkedin: Ioannis Kousis
- E-mail: jgkousis@gmail.com
📝 This project is MIT licensed.