diff --git a/TypeScript-WarmUp/ScrabbleWords.js b/TypeScript-WarmUp/ScrabbleWords.js new file mode 100644 index 0000000..1a715ff --- /dev/null +++ b/TypeScript-WarmUp/ScrabbleWords.js @@ -0,0 +1,25 @@ +"use strict"; +exports.__esModule = true; +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 scoreLetter(letter) { + return letterScores[letter]; +} +function normalizeInput(input) { + return (input || '').toUpperCase(); +} +function score(input) { + return Array.from(normalizeInput(input), scoreLetter).reduce(function (x, y) { return x + y; }, 0); +} + +console.log(score("Batool")); + + +exports["default"] = score; \ No newline at end of file diff --git a/TypeScript-WarmUp/ScrabbleWords.ts b/TypeScript-WarmUp/ScrabbleWords.ts new file mode 100644 index 0000000..a0eb366 --- /dev/null +++ b/TypeScript-WarmUp/ScrabbleWords.ts @@ -0,0 +1,26 @@ +const letterScores: { [letter: string]: number } = { + 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 scoreLetter(letter: string): number +{ + return letterScores[letter] +} + +function normalizeInput(input: string | undefined) +{ + return (input || '').toUpperCase() +} + +export default function score(input: string | undefined): number +{ + return Array.from(normalizeInput(input), scoreLetter).reduce((x, y) => x + y, 0) +} + +console.log(score("Batool")); \ No newline at end of file