0
0
Fork 0

Fix Performance/Sum cop (#24788)

This commit is contained in:
Matt Jankowski 2023-05-02 10:10:40 -04:00 committed by GitHub
parent 41eb49b984
commit 5e060e1f44
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 3 additions and 11 deletions

View file

@ -173,7 +173,7 @@ module Paperclip
def palette_from_histogram(result, quantity)
frequencies = result.scan(/([0-9]+)\:/).flatten.map(&:to_f)
hex_values = result.scan(/\#([0-9A-Fa-f]{6,8})/).flatten
total_frequencies = frequencies.reduce(&:+).to_f
total_frequencies = frequencies.sum.to_f
frequencies.map.with_index { |f, i| [f / total_frequencies, hex_values[i]] }
.sort_by { |r| -r[0] }