From 67fad8c95e5ab01a050071914bd19297a1332fef Mon Sep 17 00:00:00 2001 From: Abby Date: Tue, 6 Jun 2023 22:54:14 -0400 Subject: [PATCH 1/8] translation phase 1 complete all code is on the page half of tests passing for wave 1 and 2 --- src/adagrams.js | 121 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 117 insertions(+), 4 deletions(-) diff --git a/src/adagrams.js b/src/adagrams.js index 7ec5afc7..5154344c 100644 --- a/src/adagrams.js +++ b/src/adagrams.js @@ -1,15 +1,128 @@ +const LETTER_POOL = { + 'A': 9, + 'B': 2, + 'C': 2, + 'D': 4, + 'E': 12, + 'F': 2, + 'G': 3, + 'H': 2, + 'I': 9, + 'J': 1, + 'K': 1, + 'L': 4, + 'M': 2, + 'N': 6, + 'O': 8, + 'P': 2, + 'Q': 1, + 'R': 6, + 'S': 4, + 'T': 6, + 'U': 4, + 'V': 2, + 'W': 2, + 'X': 1, + 'Y': 2, + 'Z': 1 +}; +let letterList = []; +for (let letter in LETTER_POOL) { + // console.log(`letter ${LETTER_POOL[letter]}`) + letterList += letter.repeat(LETTER_POOL[letter]) +} +console.log(letterList) + + +let randomIndex = (letterList) => { + let index = Math.floor(Math.random() * letterList.length); + return letterList[index]; + }; + + export const drawLetters = () => { // Implement this method for wave 1 + let selectedLetters = []; + + + + while (selectedLetters.length < 10) { + + + + let chosenLetter = randomIndex(letterList);{ + if (selectedLetters.reduce((count, letter) => count + (letter === chosenLetter ? 1 : 0), 0) < LETTER_POOL[chosenLetter]){ + selectedLetters.push(chosenLetter);} + // console.log(selectedLetters);} + else { + continue; + }} + + + return selectedLetters; + }; + + }; + +console.log(drawLetters()) + export const usesAvailableLetters = (input, lettersInHand) => { // Implement this method for wave 2 + + let clone = {...lettersInHand} + + for (let character of input.toUpperCase()){ + if (character in clone){ + clone.pop(character); + } + else { + return false; + }; + }; + return true; + + }; export const scoreWord = (word) => { - // Implement this method for wave 3 -}; + let wordScore = 0; + const scores = {"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}; + + for (let letter of word.toUpperCase()){ + // word_score += scores[letter] + console.log(scores[letter]) + if (word.length >= 7){ + wordScore += 8}; -export const highestScoreFrom = (words) => { - // Implement this method for wave 4 + return wordScore; + } }; + +// export const highestScoreFrom = (words) => { +// let winningWord = ''; + +// let highestScore = 0; +// for (let word of words){ +// let wordScore = scoreWord(word); + +// if (wordScore > highestScore){ +// highestScore = wordScore; +// winningWord = word; +// } else if (wordScore === highestScore);{ +// if (winningWord.length === 10) +// continue; +// else if (word.length < winningWord.length && winningWord.length != 10);{ +// winningWord = word; +// } +// // else if (word.length == 10 && winningWord.length != 10) +// // winning_word = word; +// // } + + + +// // }; + +// return [winning_word, highest_score]; +// }; From 7306187c5c868944348487ccc8aef39796c22b2a Mon Sep 17 00:00:00 2001 From: Abby Date: Tue, 6 Jun 2023 23:12:17 -0400 Subject: [PATCH 2/8] wave one passsing --- src/adagrams.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/adagrams.js b/src/adagrams.js index 5154344c..3ad282d4 100644 --- a/src/adagrams.js +++ b/src/adagrams.js @@ -50,18 +50,16 @@ export const drawLetters = () => { - let chosenLetter = randomIndex(letterList);{ + let chosenLetter = randomIndex(letterList); if (selectedLetters.reduce((count, letter) => count + (letter === chosenLetter ? 1 : 0), 0) < LETTER_POOL[chosenLetter]){ selectedLetters.push(chosenLetter);} // console.log(selectedLetters);} else { continue; - }} - - + } + + } return selectedLetters; - }; - }; @@ -77,6 +75,7 @@ export const usesAvailableLetters = (input, lettersInHand) => { if (character in clone){ clone.pop(character); } + else { return false; }; @@ -91,8 +90,8 @@ export const scoreWord = (word) => { const scores = {"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}; for (let letter of word.toUpperCase()){ - // word_score += scores[letter] - console.log(scores[letter]) + wordScore += scores[letter] + console.log(`score:${scores[letter]}`) if (word.length >= 7){ wordScore += 8}; From 40d01ad27901f1cf44b9401a511014b2f01bdbe8 Mon Sep 17 00:00:00 2001 From: Abby Date: Wed, 7 Jun 2023 00:03:28 -0400 Subject: [PATCH 3/8] working functionality in phase three score word, missing one test pass --- src/adagrams.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/adagrams.js b/src/adagrams.js index 3ad282d4..64738c7a 100644 --- a/src/adagrams.js +++ b/src/adagrams.js @@ -78,8 +78,8 @@ export const usesAvailableLetters = (input, lettersInHand) => { else { return false; - }; - }; + } + } return true; @@ -89,16 +89,28 @@ export const scoreWord = (word) => { let wordScore = 0; const scores = {"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}; + if (word === ""){ + return wordScore; + } + + if (word.length < 1){ + // wordScore = 0 + return wordScore; + } + for (let letter of word.toUpperCase()){ wordScore += scores[letter] - console.log(`score:${scores[letter]}`) + console.log(`score:${scores[letter]}`)} if (word.length >= 7){ - wordScore += 8}; + wordScore += 8} + return wordScore; - } + }; +// console.log(scoreWord("word")) + // export const highestScoreFrom = (words) => { // let winningWord = ''; From 81970a45e7e678213227a44c93017c1f5e13147c Mon Sep 17 00:00:00 2001 From: Abby Date: Wed, 7 Jun 2023 07:19:00 -0400 Subject: [PATCH 4/8] test syntax completed --- test/adagrams.test.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/adagrams.test.js b/test/adagrams.test.js index 1a0dc94e..f4a91d27 100644 --- a/test/adagrams.test.js +++ b/test/adagrams.test.js @@ -120,7 +120,9 @@ describe("Adagrams", () => { }); it("returns a score of 0 if given an empty input", () => { - throw "Complete test"; + expectScores({ + "": 0 + }) }); it("adds an extra 8 points if word is 7 or more characters long", () => { @@ -133,7 +135,7 @@ describe("Adagrams", () => { }); }); - describe.skip("highestScoreFrom", () => { + describe("highestScoreFrom", () => { it("returns a hash that contains the word and score of best word in an array", () => { const words = ["X", "XX", "XXX", "XXXX"]; const correct = { word: "XXXX", score: scoreWord("XXXX") }; @@ -145,7 +147,8 @@ describe("Adagrams", () => { const words = ["XXX", "XXXX", "X", "XX"]; const correct = { word: "XXXX", score: scoreWord("XXXX") }; - throw "Complete test by adding an assertion"; + expect(highestScoreFrom(words)).toEqual(correct); + expect(highestScoreFrom(correct[score])).toequal(32) }); describe("in case of tied score", () => { From e6de10e88047843954445ce3a3c4901993b15d0c Mon Sep 17 00:00:00 2001 From: Abby Date: Wed, 7 Jun 2023 07:38:58 -0400 Subject: [PATCH 5/8] hgihestScoreFrom functionality completed, two tests total failing --- src/adagrams.js | 50 ++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/adagrams.js b/src/adagrams.js index 64738c7a..b45eb511 100644 --- a/src/adagrams.js +++ b/src/adagrams.js @@ -111,29 +111,29 @@ export const scoreWord = (word) => { // console.log(scoreWord("word")) -// export const highestScoreFrom = (words) => { -// let winningWord = ''; +export const highestScoreFrom = (words) => { + let winningWord = ''; -// let highestScore = 0; -// for (let word of words){ -// let wordScore = scoreWord(word); - -// if (wordScore > highestScore){ -// highestScore = wordScore; -// winningWord = word; -// } else if (wordScore === highestScore);{ -// if (winningWord.length === 10) -// continue; -// else if (word.length < winningWord.length && winningWord.length != 10);{ -// winningWord = word; -// } -// // else if (word.length == 10 && winningWord.length != 10) -// // winning_word = word; -// // } - - - -// // }; - -// return [winning_word, highest_score]; -// }; + let highestScore = 0; + for (let word of words){ + let wordScore = scoreWord(word); + + if (wordScore > highestScore){ + highestScore = wordScore; + winningWord = word; + } + else if (wordScore === highestScore) { + if (winningWord.length === 10){ + continue; + } + else if (word.length < winningWord.length && winningWord.length != 10){ + winningWord = word; + } + else if (word.length === 10 && winningWord.length != 10){ + winningWord = word + } + } + } + + return {"score": highestScore, "word": winningWord} +}; From 3386adfc66be8f29e4564d20e4a8c8f17792cbc8 Mon Sep 17 00:00:00 2001 From: Abby Date: Wed, 7 Jun 2023 11:30:46 -0400 Subject: [PATCH 6/8] passing tests --- src/adagrams.js | 29 +++++++++++++---------------- test/adagrams.test.js | 1 - 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/adagrams.js b/src/adagrams.js index b45eb511..8d4ad77a 100644 --- a/src/adagrams.js +++ b/src/adagrams.js @@ -31,7 +31,7 @@ for (let letter in LETTER_POOL) { // console.log(`letter ${LETTER_POOL[letter]}`) letterList += letter.repeat(LETTER_POOL[letter]) } -console.log(letterList) +// console.log(letterList) let randomIndex = (letterList) => { @@ -64,27 +64,26 @@ export const drawLetters = () => { }; -console.log(drawLetters()) +// console.log(drawLetters()) export const usesAvailableLetters = (input, lettersInHand) => { // Implement this method for wave 2 - let clone = {...lettersInHand} - - for (let character of input.toUpperCase()){ - if (character in clone){ - clone.pop(character); - } - - else { - return false; + let clone = [...lettersInHand] + + for (let character of input.toUpperCase()){ + if (clone.includes(character)===true){ + let cloneIndex = clone.indexOf(character) + clone.splice(cloneIndex, 1) + } else { + return false } } - return true; - + return true }; + export const scoreWord = (word) => { let wordScore = 0; const scores = {"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}; @@ -94,13 +93,11 @@ export const scoreWord = (word) => { } if (word.length < 1){ - // wordScore = 0 return wordScore; } for (let letter of word.toUpperCase()){ - wordScore += scores[letter] - console.log(`score:${scores[letter]}`)} + wordScore += scores[letter]} if (word.length >= 7){ wordScore += 8} diff --git a/test/adagrams.test.js b/test/adagrams.test.js index f4a91d27..8aa0793f 100644 --- a/test/adagrams.test.js +++ b/test/adagrams.test.js @@ -148,7 +148,6 @@ describe("Adagrams", () => { const correct = { word: "XXXX", score: scoreWord("XXXX") }; expect(highestScoreFrom(words)).toEqual(correct); - expect(highestScoreFrom(correct[score])).toequal(32) }); describe("in case of tied score", () => { From a727579ce7be6250cae93013e01edbc0b0bb86bf Mon Sep 17 00:00:00 2001 From: Mikelle Wade Date: Wed, 3 Apr 2024 01:20:09 -0400 Subject: [PATCH 7/8] changed --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index f3b45d47..cb49c9c4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:16.10.0-alpine3.14 +FROM node:20.11.0-alpine3.18 LABEL maintainer="chris.adadev.org" From dd89ff3e83e691ae669c85697f46e182a2641d50 Mon Sep 17 00:00:00 2001 From: Mikelle Wade Date: Wed, 3 Apr 2024 01:25:59 -0400 Subject: [PATCH 8/8] pushed to wrong repo --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index cb49c9c4..f3b45d47 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:20.11.0-alpine3.18 +FROM node:16.10.0-alpine3.14 LABEL maintainer="chris.adadev.org"