diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..f75fa828 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,18 @@ +{ + "workbench.colorCustomizations": { + "activityBar.background": "#1accff", + "activityBar.activeBorder": "#df00ad", + "activityBar.foreground": "#15202b", + "activityBar.inactiveForeground": "#15202b99", + "activityBarBadge.background": "#df00ad", + "activityBarBadge.foreground": "#e7e7e7", + "titleBar.activeBackground": "#00b3e6", + "titleBar.inactiveBackground": "#00b3e699", + "titleBar.activeForeground": "#15202b", + "titleBar.inactiveForeground": "#15202b99", + "statusBar.background": "#00b3e6", + "statusBarItem.hoverBackground": "#008bb3", + "statusBar.foreground": "#15202b" + }, + "peacock.color": "#00b3e6" +} \ No newline at end of file diff --git a/src/adagrams.js b/src/adagrams.js index 54043451..d175b4e6 100644 --- a/src/adagrams.js +++ b/src/adagrams.js @@ -1,8 +1,68 @@ -const Adagrams = { - drawLetters() { - // Implement this method for wave 1 +let allLetters = { + A: 9, N: 6, B: 2, O: 8, C: 2, P: 2, D: 4, Q: 1, E: 12, R: 6, F: 2, S: 4, G: 3, T: 6, H: 2, U: 4, I: 9, V: 2, J: 1, W: 2, K: 1, X: 1, L: 4, Y: 2, M: 2, Z: 1 }; + + let 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 }; + + const Adagrams = { + drawLetters() { + let letters = []; + for(let letter in allLetters) { + for(let i = 0; i < allLetters[letter]; i += 1) { + letters.push(letter); + } + } + + const myHand = []; + + for(let i = 0; i < 10; i += 1) { + const myShuffledLetters = Math.floor(Math.random(letters) * (letters.length)); + myHand.push(letters[myShuffledLetters]); + } + return myHand; }, -}; -// Do not remove this line or your tests will break! + usesAvailableLetters(input, lettersInHand) { + const wordInput = input.toUpperCase().split(""); + if (wordInput.length > lettersInHand.length) return false + const howManyTimes = {} + for(let i = 0; i < lettersInHand.length; i += 1) { + let char = lettersInHand[i]; + if (howManyTimes[char]) { + howManyTimes[char] += 1; //if it exists, increment + } else { + howManyTimes[char] = 1; + } + } + + for(let i = 0; i < wordInput.length; i += 1) { + let char = wordInput[i]; + if (howManyTimes[char]) { + if (howManyTimes[char] > 0) { + howManyTimes[char] -= 1; + } else { + return false; + } + } else if (!howManyTimes[wordInput[i]]) { + return false; + } + } + return true; + }, + + scoreWord(word) { + let thisTotal = 0; + const newWord = word.toUpperCase().split(""); + newWord.forEach((letter) => { + thisTotal += letterScores[letter]; + }); + if (word.length >= 7) { + return thisTotal + 8; + } else { + return thisTotal; + } + } +} + +// Do not remove this line or your tests will break export default Adagrams; diff --git a/test/adagrams.test.js b/test/adagrams.test.js index 371027a0..d3ec56e7 100644 --- a/test/adagrams.test.js +++ b/test/adagrams.test.js @@ -4,7 +4,6 @@ describe('Adagrams', () => { describe('drawLetters', () => { it('draws ten letters from the letter pool', () => { const drawn = Adagrams.drawLetters(); - expect(drawn).toHaveLength(10); });