From 44015976d6d0e6effbff2db9132757e0fb562c8b Mon Sep 17 00:00:00 2001 From: ohcloud Date: Sun, 17 Nov 2019 12:13:32 -0800 Subject: [PATCH 1/8] made tiles into an object. working on pulling 10 tiles next. note, i got very lost in the syntax and what i thought wasnt working at all was working all along --- .vscode/settings.json | 18 ++++++++++++++++++ src/adagrams.js | 25 ++++++++++++++++++++----- 2 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 .vscode/settings.json 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..1b96b272 100644 --- a/src/adagrams.js +++ b/src/adagrams.js @@ -1,8 +1,23 @@ -const Adagrams = { +const 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 } //this is now an object + +const Adagrams = { //this is wave one drawLetters() { - // Implement this method for wave 1 - }, -}; + let letters = []; + for(let letter in allLetters) { + for(let i = 0; i < allLetters[letter]; i += 1) { + letters.push(letter); + } + } + return letters; + } +} + +console.log(Adagrams.drawLetters()) + + + + // Do not remove this line or your tests will break! -export default Adagrams; +export default Adagrams; \ No newline at end of file From 474e49cd4a2e3468520a738f746d7300887de5f3 Mon Sep 17 00:00:00 2001 From: ohcloud Date: Sun, 17 Nov 2019 15:53:10 -0800 Subject: [PATCH 2/8] wave ome completed, randomizing properly --- src/adagrams.js | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/adagrams.js b/src/adagrams.js index 1b96b272..47c7eae9 100644 --- a/src/adagrams.js +++ b/src/adagrams.js @@ -1,23 +1,32 @@ -const 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 } //this is now an object +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 }; //this is now an object -const Adagrams = { //this is wave one - drawLetters() { - let letters = []; - for(let letter in allLetters) { - for(let i = 0; i < allLetters[letter]; i += 1) { - letters.push(letter); - } +// const drawLetters = function() {//doesnt work with this, sorry + let letters = []; + for(let letter in allLetters) { + for(let i = 0; i < allLetters[letter]; i += 1) { + letters.push(letter); } - return letters; } -} -console.log(Adagrams.drawLetters()) +const myHand = []; + +for(let i = 0; i < 10; i += 1) { + const myShuffledLetters = Math.floor(Math.random(letters) * (letters.length)); + myHand.push(letters[myShuffledLetters]); + + } + + +const Adagrams = { //this is wave one + drawLetters() { + return myHand + } +} -// Do not remove this line or your tests will break! +// Do not remove this line or your tests will break export default Adagrams; \ No newline at end of file From 360d5022f866e2411de5f764cb48bb3ca56346bf Mon Sep 17 00:00:00 2001 From: ohcloud Date: Sun, 17 Nov 2019 18:41:57 -0800 Subject: [PATCH 3/8] not decrementing properly for usesavailletters --- src/adagrams.js | 70 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 19 deletions(-) diff --git a/src/adagrams.js b/src/adagrams.js index 47c7eae9..06eb6f8b 100644 --- a/src/adagrams.js +++ b/src/adagrams.js @@ -1,32 +1,64 @@ 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 }; //this is now an object -// const drawLetters = function() {//doesnt work with this, sorry - let letters = []; - for(let letter in allLetters) { - for(let i = 0; i < allLetters[letter]; i += 1) { - letters.push(letter); + const Adagrams = { + drawLetters() {//doesnt work with this, sorry + 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]); } - } - -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; + }, + 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; + } -const Adagrams = { //this is wave one - - drawLetters() { - return myHand - } + + + + } } +console.log(Adagrams.usesAvailableLetters("hellll", ["K","H","E","L","L","O","P","A"])); +// console.log(Adagrams.drawLetters()) +// Do not remove this line or your tests will break +// export default Adagrams; + // const input = input.toUpperCase().split(""); //now an array + // const copyMyHand = [...myHand]; //copy of my hand -// Do not remove this line or your tests will break -export default Adagrams; \ No newline at end of file + // if (copyMyHand.includes(input[i])).pop \ No newline at end of file From 7fd844a96b9995f448025ab94443556e6687410d Mon Sep 17 00:00:00 2001 From: ohcloud Date: Sun, 17 Nov 2019 18:44:36 -0800 Subject: [PATCH 4/8] fixed it, its returning true or false depending on string --- test/adagrams.test.js | 1 - 1 file changed, 1 deletion(-) 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); }); From aa19ae7c5b8d6d40c376697c7155263478c137ac Mon Sep 17 00:00:00 2001 From: ohcloud Date: Sun, 17 Nov 2019 19:02:03 -0800 Subject: [PATCH 5/8] worked out the math for score word --- src/adagrams.js | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/adagrams.js b/src/adagrams.js index 06eb6f8b..d44ae5d9 100644 --- a/src/adagrams.js +++ b/src/adagrams.js @@ -1,5 +1,12 @@ 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 }; //this is now an object + 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() {//doesnt work with this, sorry @@ -43,22 +50,27 @@ let allLetters = { } else if (!howManyTimes[wordInput[i]]) { return false; } - return true; - } - - - - } + 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; + } + } } -console.log(Adagrams.usesAvailableLetters("hellll", ["K","H","E","L","L","O","P","A"])); + +// console.log(Adagrams.usesAvailableLetters("hellll", ["K","H","E","L","L","O","P","A"])); +// console.log(Adagrams.scoreWord("aaaaaaaaa")); // console.log(Adagrams.drawLetters()) // Do not remove this line or your tests will break // export default Adagrams; - - // const input = input.toUpperCase().split(""); //now an array - // const copyMyHand = [...myHand]; //copy of my hand - - // if (copyMyHand.includes(input[i])).pop \ No newline at end of file From 2165c53604775c5625de9e8fac30685c77013364 Mon Sep 17 00:00:00 2001 From: ohcloud Date: Sun, 17 Nov 2019 19:03:15 -0800 Subject: [PATCH 6/8] erased comments --- src/adagrams.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/adagrams.js b/src/adagrams.js index d44ae5d9..7936eed7 100644 --- a/src/adagrams.js +++ b/src/adagrams.js @@ -68,9 +68,5 @@ let allLetters = { } } -// console.log(Adagrams.usesAvailableLetters("hellll", ["K","H","E","L","L","O","P","A"])); -// console.log(Adagrams.scoreWord("aaaaaaaaa")); -// console.log(Adagrams.drawLetters()) - // Do not remove this line or your tests will break -// export default Adagrams; +export default Adagrams; From 2cdd4577e11be38a721cc24d1267a18ffb5f4904 Mon Sep 17 00:00:00 2001 From: ohcloud Date: Sun, 17 Nov 2019 19:04:01 -0800 Subject: [PATCH 7/8] just wanted to double check its all ok, it is. --- src/adagrams.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adagrams.js b/src/adagrams.js index 7936eed7..9847f647 100644 --- a/src/adagrams.js +++ b/src/adagrams.js @@ -9,7 +9,7 @@ let allLetters = { }; const Adagrams = { - drawLetters() {//doesnt work with this, sorry + drawLetters() { let letters = []; for(let letter in allLetters) { for(let i = 0; i < allLetters[letter]; i += 1) { From afb3eb68c57fba236f06d3d4488a650dd2b45bd0 Mon Sep 17 00:00:00 2001 From: ohcloud Date: Sun, 17 Nov 2019 19:05:16 -0800 Subject: [PATCH 8/8] fixed formatting --- src/adagrams.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/adagrams.js b/src/adagrams.js index 9847f647..d175b4e6 100644 --- a/src/adagrams.js +++ b/src/adagrams.js @@ -2,11 +2,7 @@ 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 - }; + 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() {