Sha256: 378bc2d0031fdb10633105d0be687a3f7a9a5cca37af737b33839562ff38488d

Contents?: true

Size: 549 Bytes

Versions: 105

Compression:

Stored size: 549 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 (wrd) {
  var word = wrd ? wrd.toLowerCase() : '';

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

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

  return sum;
};

Version data entries

105 entries across 105 versions & 1 rubygems

Version Path
trackler-2.2.1.119 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.118 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.117 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.116 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.115 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.114 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.113 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.111 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.110 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.109 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.108 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.107 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.106 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.105 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.104 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.103 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.102 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.101 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.100 tracks/javascript/exercises/scrabble-score/example.js
trackler-2.2.1.99 tracks/javascript/exercises/scrabble-score/example.js