Sha256: a50011949ec1b63bba4e13ada8ed619f335fe671f728b6c062453ed1971a8b5c

Contents?: true

Size: 616 Bytes

Versions: 4

Compression:

Stored size: 616 Bytes

Contents

# frozen_string_literal: true

module Codebreaker
  module Entities
    class Statistics
      def stats(list)
        difficulties = list.group_by { |score| score[:difficulty] }
        %i[hell 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_used], score[:hints_used]] }
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
codebreaker_marian-0.2.8 lib/codebreaker_marian/entities/statistics.rb
codebreaker_marian-0.2.7 lib/codebreaker_marian/entities/statistics.rb
codebreaker_marian-0.2.6 lib/codebreaker_marian/entities/statistics.rb
codebreaker_marian-0.2.5 lib/codebreaker_marian/entities/statistics.rb