DEV Community

vicky9812
vicky9812

Posted on

please solved this i don know how to solved this

Scrabble Scores
Each letter (tile) in scrabble is worth a certain number of points.
Build an algorithm that calculates the total scrabble tile score of all the letters in a file.
For example, the following file with this content;
Founded in 2012 in Noida, Ad2click Media mission is to help the world put
software to work in new ways, through the delivery of effective learning and
information services to IT professionals.
Will score 257 :
We do this by adding scrabble tile scores together FOUNDED for example would be 4 + 1 + 1+
1+2+1+2 = 12 (as F=4, O=1, U=1 etc…)
We ignore punctuation, spaces and numbers.
What is the point score for all the letters found in the complete works of Shakespeare found at
https://www.gutenberg.org/cache/epub/100/pg100.txt?

Top comments (1)

Collapse
 
ant_f_dev profile image
Anthony Fung

Something like this would do it. You'd need to get replace the value of characters though.

const characters = Array.from(`
Founded in 2012 in Noida, Ad2click Media mission is to help the world put
software to work in new ways, through the delivery of effective learning and
information services to IT professionals.`);

let total = 0;

const scores = {
  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
};

for (let i = 0; i < characters.length; i++) {
  const character = characters[i].toLowerCase();
  const points = scores[character];  
  if (typeof points === 'number') {
    total += points;
  }
}

console.log(total);
Enter fullscreen mode Exit fullscreen mode