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

Sea Turtles JS-Adagrams -Tyrah G. #103

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

Conversation

ursaturnine
Copy link

Still fixing wave 3

Copy link

@anselrognlie anselrognlie left a comment

Choose a reason for hiding this comment

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

Nice work.

Your overall approaches are good, but really pay attention to those details. For instance, drawLetters currently returns the same letters with every call. I definitely see your intention, but be sure to double check your code. The tests only check for impossible hands, but it shows up in the demo game. usesAvailableLetters also has an issue due to how the hand is being used. Also, think about how your variable names imply what they contain. Like python, JS variables can refer to anything, so giving care to how we name them can make our code easier to understand and maintain.

But overall, good job.

@@ -0,0 +1,57 @@
export const LETTER_POOL = {

Choose a reason for hiding this comment

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

Nice way to avoid cluttering up the logic file with these massive constants!

Comment on lines +5 to +10
let letterPool = [];
for (const [key, value] of Object.entries(LETTER_POOL)) {
for (let i = 0; i < value; i++) {
letterPool.push(key);
}
}

Choose a reason for hiding this comment

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

Great way to build up the pool of tiles to draw from.

Since we modify only the contents of letterPool, it could still be declared with const since we never reassign the variable.

export const drawLetters = () => {
// Implement this method for wave 1
let letterPool = createLetterPool();
let letterPoolDeepCopy = JSON.parse(JSON.stringify(letterPool));

Choose a reason for hiding this comment

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

Since you build a new `letterPool' whenever this function is called, there's no need to make another copy.

Comment on lines +18 to +23
function shuffleArray(letterPoolDeepCopy) {
for (let i = 0; i < letterPoolDeepCopy; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}

Choose a reason for hiding this comment

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

This function is defined, but never called. As a result, every hand we get is always A A A A A A A A A B. We now have scrabble for 🐑! 😁

I'd suggest moving this out of this function since it doesn't really need to be defined inside the drawLetters function. That would also make it easier to see that it wasn't being used yet, which is really the only issue here.

[array[i], array[j]] = [array[j], array[i]];
}
}
let letterBank = letterPoolDeepCopy.slice(0, 10);

Choose a reason for hiding this comment

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

This is a great way to get the first 10 items out of the list.

We can declare letterBank with const.

if (lettersInHand.includes(char) === false) {
return false;
} else if (lettersInHand.includes(char)) {
lettersInHand.splice(char[letters], 1);

Choose a reason for hiding this comment

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

This isn't working properly. It appears to because the letters in the word and hand apparently line up in the tests.

But really, splice takes a position as its first argument. char will be a single-letter string (we looked it up from the word) and any index lookup greater than position 0 (so anything but the first letter would be passing in undefined). But whether a letter or undefined, it's having the effect of removing the first element from the list.

We can see this with this example

usesAvailableLetters('cat', ['t', 'a', 'c'])

which should be true, but returns false.

So we would need to find the position of a letter to splice out of the array before doing the splice. Check out indexOf as an alternative to includes.

Also, we don't want to modify that hand that was passed in. So if we're doing to take a destructive (to the hand) approach here, we would want to make a local copy before modifying it.

Comment on lines +45 to +47
if (input.toUpperCase() in SCORE_CHART) {
score += SCORE_CHART[input.toUpperCase()];
}

Choose a reason for hiding this comment

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

Nice thought to add this bit of additional safety.

It wasn't a requirement, though in the context of these functions, we might expect to only receive words that are made of valid letter tiles.

Often, when there are a bunch of functions working together in a larger system, we'll expect the validation to have been at one central point so that we don't need to think about so many edge cases in the rest of our code.

But nice overall approach of iterating over the word, looking up the score of each letter, and adding the bonus if needed.

} else if (wordScore === maxScore) {
let wordLen = input.length;
let highScoreWordLen = highScoreWord.length;
{

Choose a reason for hiding this comment

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

No need to introduce a block here.

let maxScore = 0;
let highScoreWord = "";

for (let word = 0; word < words.length; word++) {

Choose a reason for hiding this comment

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

Nice job. Your cascading checks are pretty easy to follow!

Here, consider a iteration variable name that indicates that this is numeric (word_pos, or even simply i). word sounds like it should contain a string.

Comment on lines +123 to +125
expectScores({
"": 0,
});

Choose a reason for hiding this comment

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

Nice use of the helper.

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