mirror of
https://github.com/red-data-tools/YouPlot.git
synced 2025-05-06 23:21:13 +08:00
25 lines
566 B
Ruby
25 lines
566 B
Ruby
![]() |
# frozen_string_literal: true
|
||
|
|
||
|
module YouPlot
|
||
|
# plotting functions.
|
||
|
module Backends
|
||
|
module Processing
|
||
|
module_function
|
||
|
|
||
|
def count_values(arr)
|
||
|
# tally was added in Ruby 2.7
|
||
|
if Enumerable.method_defined? :tally
|
||
|
arr.tally
|
||
|
else
|
||
|
# https://github.com/marcandre/backports
|
||
|
arr.each_with_object(Hash.new(0)) { |item, res| res[item] += 1 }
|
||
|
.tap { |h| h.default = nil }
|
||
|
end
|
||
|
.sort { |a, b| a[1] <=> b[1] }
|
||
|
.reverse
|
||
|
.transpose
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|