mirror of
https://github.com/red-data-tools/YouPlot.git
synced 2025-05-06 15:11:12 +08:00
25 lines
589 B
Ruby
25 lines
589 B
Ruby
# frozen_string_literal: true
|
|
|
|
module YouPlot
|
|
# plotting functions.
|
|
module Backends
|
|
module Processing
|
|
module_function
|
|
|
|
def count_values(arr, tally: true)
|
|
# tally was added in Ruby 2.7
|
|
if tally && 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
|