Open
Conversation
…count for empty str input
ameerrah9
reviewed
Jun 20, 2023
Comment on lines
+2
to
+15
| 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'), |
There was a problem hiding this comment.
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?
ameerrah9
reviewed
Jun 20, 2023
Comment on lines
+32
to
+38
| 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); | ||
| } |
ameerrah9
reviewed
Jun 20, 2023
Comment on lines
+46
to
+55
| const handCopy = [...lettersInHand]; | ||
|
|
||
| for (const letter of input) { | ||
| const index = handCopy.indexOf(letter); | ||
|
|
||
| if (index === -1) { | ||
| return false; | ||
| } | ||
|
|
||
| handCopy.splice(index, 1); |
ameerrah9
reviewed
Jun 20, 2023
Comment on lines
+32
to
+40
| 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); | ||
| } | ||
| } | ||
|
|
ameerrah9
reviewed
Jun 20, 2023
Comment on lines
+48
to
+56
| for (const letter of input) { | ||
| const index = handCopy.indexOf(letter); | ||
|
|
||
| if (index === -1) { | ||
| return false; | ||
| } | ||
|
|
||
| handCopy.splice(index, 1); | ||
| } |
ameerrah9
reviewed
Jun 20, 2023
Comment on lines
+67
to
+85
| 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; | ||
| } |
There was a problem hiding this comment.
Great work getting comfortable with JavaScript's syntax. It looks like you're getting use to looping over data and adding conditional logic ✅
ameerrah9
reviewed
Jun 20, 2023
Comment on lines
+101
to
+103
| highestScoringWords = [{ word, score }]; | ||
| } else if (score === highestScore) { | ||
| highestScoringWords.push({ word, score }); |
There was a problem hiding this comment.
Great work using this object to implement this solution ✅
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.