Ruby Coding Practice: Building Bubble Sort From Scratch


This coding exercise walks through how to implement the Bubble Sort algorithm in Ruby and how to add it to the built in Array class.


Build the Bubble Sort algorithm from scratch and add it to the Array class in Ruby.

Exercise File

Code File

Exercise Description

Given an array of integers, such as:

arr = ['42', '8', '70']

Implement the bubble sort algorithm so that it can be called directly on an array, such as:


Sample Output

['8', '42', '70']

Real World Usage

Sorting algorithms are popular interview questions. This is mainly because sorting algorithms force you: to think logically, manage data, manipulate collections, and return accurate values. Additionally, to correctly perform this exercise you will need to implement monkey patching, which allows you to add functionality to pre-existing classes in Ruby.


Can be found on the solutions branch on github.


Please enter your comment!
Please enter your name here