Skip to content

Commit

Permalink
Finished core and extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Annemoon-de-Groen committed Feb 16, 2024
1 parent bb67a10 commit da419e4
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion src/scrabble.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,51 @@
function scrabble() {
function scrabble(word) {
if (typeof word !== 'string') return 0
let multiplier = 1
const array = word.toLowerCase().split('')
let result = 0
for (let i = 0; i < array.length; i++) {
if (array[i] in value) {
result += value[array[i]] * multiplier
continue
}
if (array[i] === '{') multiplier *= 2
else if (array[i] === '}') multiplier /= 2
else if (array[i] === '[') multiplier *= 3
else if (array[i] === ']') multiplier /= 3
else return 0
}
if (multiplier !== 1) return 0
return result
// write code here
}

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

module.exports = scrabble

0 comments on commit da419e4

Please sign in to comment.