-
Notifications
You must be signed in to change notification settings - Fork 169
Amethyst - Hannah Watkins #142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
bf7f903
acec02d
55f5baa
d443696
ecd037e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,122 @@ | ||
| export const drawLetters = () => { | ||
| // Implement this method for wave 1 | ||
| const letterPool = [ | ||
| ...Array(9).fill('A'), | ||
| ...Array(2).fill('B'), | ||
| ...Array(2).fill('C'), | ||
| ...Array(4).fill('D'), | ||
| ...Array(12).fill('E'), | ||
| ...Array(2).fill('F'), | ||
| ...Array(3).fill('G'), | ||
| ...Array(2).fill('H'), | ||
| ...Array(9).fill('I'), | ||
| 'J', | ||
| 'K', | ||
| ...Array(4).fill('L'), | ||
| ...Array(2).fill('M'), | ||
| ...Array(6).fill('N'), | ||
| ...Array(8).fill('O'), | ||
| ...Array(2).fill('P'), | ||
| 'Q', | ||
| ...Array(6).fill('R'), | ||
| ...Array(4).fill('S'), | ||
| ...Array(6).fill('T'), | ||
| ...Array(4).fill('U'), | ||
| ...Array(2).fill('V'), | ||
| ...Array(2).fill('W'), | ||
| 'X', | ||
| ...Array(2).fill('Y'), | ||
| 'Z', | ||
| ]; | ||
| const hand = []; | ||
|
|
||
| while (hand.length < 10) { | ||
| const randomIndex = Math.floor(Math.random() * letterPool.length); | ||
| const letter = letterPool[randomIndex]; | ||
|
|
||
| if (hand.filter((l) => l === letter).length < letterPool.filter((l) => l === letter).length) { | ||
| hand.push(letter); | ||
| } | ||
|
Comment on lines
+32
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice use of |
||
| } | ||
|
|
||
|
Comment on lines
+32
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice job translating this logic 👍🏾 |
||
| return hand; | ||
| }; | ||
|
|
||
| // check for input validity - can given letters form word | ||
| export const usesAvailableLetters = (input, lettersInHand) => { | ||
| // Implement this method for wave 2 | ||
| const handCopy = [...lettersInHand]; | ||
|
|
||
| for (const letter of input) { | ||
| const index = handCopy.indexOf(letter); | ||
|
|
||
| if (index === -1) { | ||
| return false; | ||
| } | ||
|
|
||
| handCopy.splice(index, 1); | ||
|
Comment on lines
+46
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice job translating this logic 👍🏾 |
||
| } | ||
|
Comment on lines
+48
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great work! |
||
|
|
||
| return true; | ||
| }; | ||
|
|
||
| // calculate score for a word | ||
| export const scoreWord = (word) => { | ||
| // Implement this method for wave 3 | ||
| if (word === "") { | ||
| return 0; | ||
| } | ||
|
|
||
| const 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, | ||
| }; | ||
|
|
||
| let score = 0; | ||
|
|
||
| for (const letter of word.toUpperCase()) { | ||
| score += letterScores[letter]; | ||
| } | ||
|
|
||
| if (word.length >= 7 && word.length <= 10) { | ||
| score += 8; | ||
| } | ||
|
Comment on lines
+67
to
+85
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great work getting comfortable with JavaScript's syntax. It looks like you're getting use to looping over data and adding conditional logic ✅ |
||
|
|
||
| return score; | ||
| }; | ||
|
|
||
|
|
||
| // find word w/ highest score | ||
| export const highestScoreFrom = (words) => { | ||
| // Implement this method for wave 4 | ||
| let highestScore = 0; | ||
| let highestScoringWords = []; | ||
|
|
||
| for (const word of words) { | ||
| const score = scoreWord(word); | ||
|
|
||
| if (score > highestScore) { | ||
| highestScore = score; | ||
| highestScoringWords = [{ word, score }]; | ||
| } else if (score === highestScore) { | ||
| highestScoringWords.push({ word, score }); | ||
|
Comment on lines
+101
to
+103
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great work using this object to implement this solution ✅ |
||
| } | ||
| } | ||
|
|
||
| if (highestScoringWords.length === 1) { | ||
| return highestScoringWords[0]; | ||
| } else { | ||
| let winningWord = highestScoringWords[0]; | ||
|
|
||
| for (const wordData of highestScoringWords) { | ||
| if (wordData.word.length === 10) { | ||
| return wordData; | ||
| } else if (wordData.word.length < winningWord.word.length && winningWord.word.length !== 10) { | ||
| winningWord = wordData; | ||
| } | ||
| } | ||
|
|
||
| return winningWord; | ||
| } | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Hannah! Great job completing JS Adagrams! Congrats on finishing your first JavaScript project 🎉 Excellent choice with this data structure. There's a lot of repeated code here, how can we make this program more DRY?