February 17 - How to Sort the Keys of a Hash in Ruby
This guide walks through how to work with Ruby hashes, specifically how to sort through the keys by length.
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
Build a method that sorts the keys in a hash by length.
Exercise Description
Given a Ruby Hash, build a method that returns an array of keys that are sorted based on length.
Sample Input
{ some_key: 'Anything', "string key" => 'Anything', 8383 => 'Does not matter' }
Expected Output
["8383", "some_key", "string key"]
Real World Usage
Working with hashes in Ruby is critical when it comes to performing tasks such as working with database queries or any type of work specific to key value based data.