Sha256: f33739942954ef8840be38e95c39229109c53fb7257702ab8b4580f9a1f32086

Contents?: true

Size: 584 Bytes

Versions: 255

Compression:

Stored size: 584 Bytes

Contents

'use strict';

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

function letterScore(letter) {
  return letterScores[letter] || 0;
}

module.exports = function(word) {
  word || (word = '');
  word = word.toLowerCase();

  var sum = 0;
  var idx = -1;
  var end = word.length;

  while (++idx < end) {
    sum += letterScore(word[idx]);
  }

  return sum;
};

Version data entries

255 entries across 255 versions & 1 rubygems

Version Path
trackler-2.2.1.37 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.36 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.35 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.34 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.33 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.32 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.31 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.30 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.29 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.28 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.27 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.26 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.25 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.24 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.23 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.22 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.21 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.20 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.19 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.18 tracks/javascript/exercises/scrabble-score/example.js