Created
December 13, 2018 00:04
-
-
Save IvikGH/edf6d4c1c5f20be77e0dec5088a34ecf to your computer and use it in GitHub Desktop.
ruby_tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sort by frequency | |
def frequency(arr) | |
arr.each_with_object(Hash.new(0)) { |letter, result| result[letter] += 1 } | |
.sort_by { |_k, v| -v }.to_h.keys | |
end | |
# Flatten a list | |
def flatten(arr) | |
arr.flatten! | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment