Sha256: 9fb813833eb95e8fdd4bbe57995d2845fe5296a77c41a849b031a0d337955906

Contents?: true

Size: 624 Bytes

Versions: 14

Compression:

Stored size: 624 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]] }.reverse
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
codebreaker_marian-0.2.4 lib/codebreaker_marian/entities/statistics.rb
codebreaker_marian-0.2.3 lib/codebreaker_marian/entities/statistics.rb
codebreaker_marian-0.2.2 lib/codebreaker_marian/entities/statistics.rb
codebreaker_marian-0.2.1 lib/codebreaker_marian/entities/statistics.rb
codebreaker_marian-0.2.0 lib/codebreaker_marian/entities/statistics.rb
codebreaker_marian-0.1.9 lib/codebreaker_marian/entities/statistics.rb
codebreaker_marian-0.1.8 lib/codebreaker_marian/entities/statistics.rb
codebreaker_marian-0.1.7 lib/codebreaker_marian/entities/statistics.rb
codebreaker_marian-0.1.6 lib/codebreaker_marian/entities/statistics.rb
codebreaker_marian-0.1.5 lib/codebreaker/entities/statistics.rb
codebreaker-yeroshek-0.1.5 lib/codebreaker/entities/statistics.rb
codebreaker-yeroshek-0.1.4 lib/codebreaker/entities/statistics.rb
codebreaker-yeroshek-0.1.3 lib/codebreaker/entities/statistics.rb
codebreaker-yeroshek-0.1.2 lib/codebreaker/entities/statistics.rb