Created
May 18, 2021 17:33
-
-
Save aarkerio/3f0a47f2f4a43b0c5534363396c5c707 to your computer and use it in GitHub Desktop.
Group and order array by frequency
This file contains 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
# Private: order companions by frequency. | |
# | |
# orders - Array of hashes. | |
# | |
# Returns Hashmap. | |
def companions(orders) | |
orders.reduce([]) {|acc, o| acc + o[:unique_product_ids]}.group_by(&:itself).transform_values!(&:size) | |
.sort{ |a,b| b.second <=> a.second }.first(15) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment