Skip to content
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 - Denise C. #39

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

C22 Sphinx - Denise C. #39

wants to merge 3 commits into from

Conversation

dpchengmath
Copy link

No description provided.

Copy link

@yangashley yangashley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work on js-adagrams!

Comment on lines +1 to +3
const handSize = 10

const letterPool = {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we use the const keyword to ensure the values cannot be reassigned, we should also use capital letters to convey to other devs the value is fixed.

Suggested change
const handSize = 10
const letterPool = {
const HAND_SIZE = 10
const LETTER_POOL = {

'Z': 1
};

const letterPointValues = {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const letterPointValues = {
const LETTER_POINT_VALUES = {

}

return listOfAllLetters;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done! I like that you put this logic in a helper function.

The blank line on line 72 should be removed. Per the Google JS styleguide: "Within method bodies, sparingly to create logical groupings of statements. Blank lines at the start or end of a function body are not allowed."

https://google.github.io/styleguide/jsguide.html

const listOfAllLetters = createLetterPool();

while (handOfLettersList.length < handSize) {
const aRandomIndexThatAccessesRandomLetter = Math.floor(Math.random() * listOfAllLetters.length);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that you don't hardcode a value and use listOfAllLetters.length

const listOfAllLetters = createLetterPool();

while (handOfLettersList.length < handSize) {
const aRandomIndexThatAccessesRandomLetter = Math.floor(Math.random() * listOfAllLetters.length);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know naming is challenging and your variable name is descriptive, but since it's so long it makes the code a little less readable to me (a subjective opinion). I'd probably name this variable something like randIndex.

export const drawLetters = () => {
// Implement this method for wave 1
const handOfLettersList = [];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Nice job using const for this list. We should always prefer to use const over let whenever possible.

const aRandomIndexThatAccessesRandomLetter = Math.floor(Math.random() * listOfAllLetters.length);
const randomLetterChosen = listOfAllLetters[aRandomIndexThatAccessesRandomLetter];
handOfLettersList.push(randomLetterChosen);
listOfAllLetters.splice(aRandomIndexThatAccessesRandomLetter, 1);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

splice like python's remove has linear time complexity with respect to the length of the list. This won't be a problem for the size of data we're working with, but consider using a strategy of virtually "dividing" the list into a used and unused side. Swapping a value to the used side would be constant time!

// Implement this method for wave 2

export const usesAvailableLetters = (word, handOfLettersList) => {
const wordBankList = [...handOfLettersList];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of the spread syntax


} else {
const index = wordBankList.indexOf(letter);
wordBankList.splice(index, 1);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like I mentioned above, splice time complexity is linear. What if you created a frequency map and then leveraged the constant look up time of an object?

After you have an object with the key being a letter and value being it's frequency in word you can use that to figure out if you have a valid word from the letters in your hand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants