February 9 - Customizing the Ruby Sort Method to Force an Element to the End of the Sorted Array
This guide walks through how to alter the built in Ruby sort method so that it forces a specific element to be placed at the end of a sorted array.
Guide Tasks
- Read Tutorial
- Watch Guide Video
- Complete the Exercise
Video locked
This video is viewable to users with a Bottega Bootcamp license
Already a Bottega Student? Sign In
Summary
Alter the built in
sort
method in Ruby so that it always places a specific element at the end of a sorted array.
Exercise Description
Given the alphabet in an array based form:
['a', 'b', 'c', ..., 'z']
Customize the sort
method so that it places the letter k
at the end of the array:
Expected Output
["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "k"]
Real World Usage
In order to build this solution, you will need to understand a number of important concepts, such as:
- How to pass a block to the
sort
method - Working with the spaceship operator for comparisons