-
Notifications
You must be signed in to change notification settings - Fork 0
/
kata32-Scrabblemania.js
82 lines (77 loc) · 1002 Bytes
/
kata32-Scrabblemania.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
function wordscore(word) {
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,
};
let total = 0;
word = word.split("");
console.log(word);
for (let element of word) {
total += scores[element];
}
console.log(word);
total *= word.length;
if (word.length === 7) {
total += 50;
}
console.log(word);
return total;
}
function wordscore(word) {
let obj = {
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,
};
return (
word.split(``).reduce((a, b) => a + obj[b], 0) * word.length +
(word.length >= 7 ? 50 : 0)
);
}