Sha256: cd358ed03c3f47a254674850070e435405a71ac42a869b3e92bbe934d60966b4

Contents?: true

Size: 597 Bytes

Versions: 9

Compression:

Stored size: 597 Bytes

Contents

module Codebreaker
  module Entities
    class Statistics
      def stats(list)
        difficulties = list.group_by { |score| score[:difficulty] }
        %i[hard medium easy].reduce([]) do |sorted_difficulties, difficulty_name|
          if difficulties[difficulty_name]
            sorted_difficulties + stats_sort(difficulties[difficulty_name])
          else
            sorted_difficulties
          end
        end
      end

      private

      def stats_sort(scores)
        scores.sort_by! { |score| [score[:attempts_wasted], score[:hints_wasted]] }.reverse
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
codebreaker_artuomka-0.1.8 lib/codebreaker/entities/statistics.rb
codebreaker_artuomka-0.1.7 lib/codebreaker/entities/statistics.rb
codebreaker_artuomka-0.1.6 lib/codebreaker/entities/statistics.rb
codebreaker_artuomka-0.1.5 lib/codebreaker/entities/statistics.rb
codebreaker_artuomka-0.1.4 lib/codebreaker/entities/statistics.rb
codebreaker_artuomka-0.1.3 lib/codebreaker/entities/statistics.rb
codebreaker_artuomka-0.1.2 lib/codebreaker/entities/statistics.rb
codebreaker_artuomka-0.1.1 lib/codebreaker/entities/statistics.rb
codebreaker_artuomka-0.1.0 lib/codebreaker/entities/statistics.rb