Sha256: bb59b5e87b6b9e5d14aba12d2c52ee5d73e86ae4db2717cd4cfb437c2c03139e

Contents?: true

Size: 607 Bytes

Versions: 396

Compression:

Stored size: 607 Bytes

Contents

class Scrabble
  def self.score(term)
    new(term).score
  end

  attr_reader :term
  def initialize(term)
    @term = term.to_s.downcase
  end

  def score
    sum = 0
    term.chars.each do |char|
      sum += letter_values.fetch(char) { 0 }
    end
    sum
  end

  def letter_values
    {
      'a' => 1, 'b' => 3, 'c' => 3, 'd' => 2, 'e' => 1,
      'f' => 4, 'g' => 2, 'h' => 4, 'i' => 1, 'j' => 8,
      'k' => 5, 'l' => 1, 'm' => 3, 'n' => 1, 'o' => 1,
      'p' => 3, 'q' => 10, 'r' => 1, 's' => 1, 't' => 1,
      'u' => 1, 'v' => 4, 'w' => 4, 'x' => 8, 'y' => 4,
      'z' => 10
    }
  end
end

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/ruby/exercises/scrabble-score/.meta/solutions/scrabble_score.rb
trackler-2.2.1.179 tracks/ruby/exercises/scrabble-score/.meta/solutions/scrabble_score.rb
trackler-2.2.1.178 tracks/ruby/exercises/scrabble-score/.meta/solutions/scrabble_score.rb
trackler-2.2.1.177 tracks/ruby/exercises/scrabble-score/.meta/solutions/scrabble_score.rb
trackler-2.2.1.176 tracks/ruby/exercises/scrabble-score/.meta/solutions/scrabble_score.rb
trackler-2.2.1.175 tracks/ruby/exercises/scrabble-score/.meta/solutions/scrabble_score.rb
trackler-2.2.1.174 tracks/ruby/exercises/scrabble-score/.meta/solutions/scrabble_score.rb
trackler-2.2.1.173 tracks/ruby/exercises/scrabble-score/.meta/solutions/scrabble_score.rb
trackler-2.2.1.172 tracks/ruby/exercises/scrabble-score/.meta/solutions/scrabble_score.rb
trackler-2.2.1.171 tracks/ruby/exercises/scrabble-score/.meta/solutions/scrabble_score.rb
trackler-2.2.1.170 tracks/ruby/exercises/scrabble-score/.meta/solutions/scrabble_score.rb
trackler-2.2.1.169 tracks/ruby/exercises/scrabble-score/.meta/solutions/scrabble_score.rb
trackler-2.2.1.167 tracks/ruby/exercises/scrabble-score/.meta/solutions/scrabble_score.rb
trackler-2.2.1.166 tracks/ruby/exercises/scrabble-score/.meta/solutions/scrabble_score.rb
trackler-2.2.1.165 tracks/ruby/exercises/scrabble-score/.meta/solutions/scrabble_score.rb
trackler-2.2.1.164 tracks/ruby/exercises/scrabble-score/.meta/solutions/scrabble_score.rb
trackler-2.2.1.163 tracks/ruby/exercises/scrabble-score/.meta/solutions/scrabble_score.rb
trackler-2.2.1.162 tracks/ruby/exercises/scrabble-score/.meta/solutions/scrabble_score.rb
trackler-2.2.1.161 tracks/ruby/exercises/scrabble-score/.meta/solutions/scrabble_score.rb
trackler-2.2.1.160 tracks/ruby/exercises/scrabble-score/.meta/solutions/scrabble_score.rb