-
Notifications
You must be signed in to change notification settings - Fork 44
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
C22 Sphinx Izzy #27
base: main
Are you sure you want to change the base?
C22 Sphinx Izzy #27
Conversation
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.
Nice work! Please let me know if there are any questions about the comments made.
@@ -1,15 +1,107 @@ | |||
'use strict'; | |||
|
|||
import { letterPool, scoreChart } from './constants.js'; |
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.
✨
for (const [letter, freq] of Object.entries(letterPoolDict)) { | ||
for (let i = 0; i < freq; i++) { | ||
letterPoolList.push(letter); | ||
} | ||
} |
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.
Something extra to think about is how you could implement this same functionality with the ...
syntax that is provided and if you think it provides any advantages against what you have.
const removeLetter = (list, letter) => { | ||
//Function has two parameters, a list and a letter, and returns a list with the letter removed | ||
const index = list.indexOf(letter); | ||
list.splice(index, 1); |
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.
These are letter counts will the same size but what if they weren't? What if the input size varied? What would be the time complexity of your code? What CS fundamentals data structure did we learn about that is handy for keeping track of the number of occurrences? Is there anything we can cross reference this data structure to?
//Function has one parameter, a dictionary, and returns a list of letters. | ||
let letterPoolList = []; | ||
|
||
for (const [letter, freq] of Object.entries(letterPoolDict)) { |
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.
Nice work finding the javascript version of .items
!
const drawnLetters = []; | ||
for (let i = 0; i < 10; i++) { | ||
const randomIndex = getRandomNumber(letterPoolList.length - 1); | ||
const letter = letterPoolList[randomIndex]; | ||
drawnLetters.push(letter); | ||
|
||
removeLetter(letterPoolList, letter); | ||
} |
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.
Love this functionality, you separate concerns, making your more digestible!
// Implement this method for wave 2 | ||
// Function checks if the input word uses available letters in the letterInHand list | ||
const wordUpperCase = input.toUpperCase(); | ||
const temporaryLetterBank = [...lettersInHand]; |
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.
...
syntax!
// Function scores the word | ||
const inputUpperCase = word.toUpperCase(); | ||
let score = 0; | ||
|
||
for (const letter of inputUpperCase) { | ||
if (scoreChart[letter]) { | ||
score += scoreChart[letter]; | ||
} | ||
} | ||
if (inputUpperCase.length >= 7) { | ||
score += 8; | ||
} | ||
return score; | ||
}; |
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.
⭐️
const findHighestScore = (words) => { | ||
//Function finds the max word score in the list | ||
const max = words.reduce((prev, current) => { | ||
if (scoreWord(current) > scoreWord(prev)) { | ||
return current; | ||
} else if (scoreWord(current) === scoreWord(prev)) { | ||
if (current.length === prev.length) { | ||
return prev; | ||
} else if (current.length === 10) { | ||
return current; | ||
} else if (prev.length === 10) { | ||
return prev; | ||
} else if (current.length < prev.length) { | ||
return current; | ||
} | ||
} | ||
return prev; | ||
}, words[0]); | ||
|
||
return max; |
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.
Love to see you using the reduce
method, you did good with this! ⭐️
No description provided.