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

Ada C22 Phoenix Class, Madina Dzhetegenova #42

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

Conversation

Madina-j
Copy link

No description provided.

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.

Looks good overall! Please review my comments, and let me know if you have any questions.

Comment on lines +29 to +31
const SCORE_CHART = {A: 1,
E: 1,
I: 1,

Choose a reason for hiding this comment

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

If the values in the object are spread across multiple lines, list the first value indented along with the remaining values. And since JS doesn't care what order the keys are listed, it would be easier for another coder reading this if the letters were written alphabetically, as it makes it easier to confirm that all the letters are present.

const SCORE_CHART = {
  A: 1,
  B: 3,
  C: 3,

Comment on lines +59 to +63
for (const [letter, count] of Object.entries(LETTER_POOL)) {
for (let i = 0; i < count; i++) {
letterPool.push(letter);
}
}

Choose a reason for hiding this comment

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

Nice logic to build a pile of all the tiles.

for (let i = 0; i < 10; i++) {
const randomIndex = Math.floor(Math.random() * letterPool.length);
handBank.push(letterPool[randomIndex]);
letterPool.splice(randomIndex, 1);

Choose a reason for hiding this comment

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

Much like pop/remove in python, splice will need to shift values forward to close the hole left by the removed item. To avoid the internal loop this requires, we can first swap it with value to the end of the pool, then pop it. Strictly speaking, it's not even necessary to remove the value from the list, so lang as we adjusted the value we used as the list length to reflect the size of the available portion of the pool.

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.

👍

@@ -133,7 +135,7 @@ describe("Adagrams", () => {
});
});

describe.skip("highestScoreFrom", () => {
describe("highestScoreFrom", () => {

Choose a reason for hiding this comment

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

👍

letter = letter.toUpperCase();

if (!lettersInHand.includes(letter)) {
return false;

Choose a reason for hiding this comment

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

It looks like your editor switched to 4 space indentations occassionally. For JS, we tend to prefer smaller indentations, since more indented code tends to be common in JS. In Python, we would use deeper indentation as a hint that maybe we should do some refactoring, but that tends not to be as true in JS.


const index = lettersInHand.indexOf(letter);
lettersInHand.splice(index, 1);
}

Choose a reason for hiding this comment

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

Nit: This closing brace became too unindented.

Comment on lines +106 to +138
let scoreMax = 0;
let wordMin = "ZZZZZZZZZZZZZZZZZ";
let wordsPosWin = [];

for (let word of words) {
const wordScore = scoreWord(word);
if (wordScore > scoreMax) {
scoreMax = wordScore;
}
}

for (let word of words) {
const wordScore = scoreWord(word);
if (wordScore === scoreMax) {
wordsPosWin.push(word);
}
}

if (wordsPosWin.length === 1) {
return {word: wordsPosWin[0], score: scoreMax};
}

for (let word of wordsPosWin) {
if (word.length === 10) {
return {word: word, score: scoreMax};
}

if (word.length < wordMin.length) {
wordMin = word;
}
}
return {word: wordMin, score: scoreMax};

Choose a reason for hiding this comment

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

This whole function became intended too deeply for some reason and is using 4 space indentations.

let wordMin = "ZZZZZZZZZZZZZZZZZ";
let wordsPosWin = [];

for (let word of words) {

Choose a reason for hiding this comment

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

For pretty much any for/of loop, prefer const (here and throughout)

Suggested change
for (let word of words) {
for (const word of words) {


export const highestScoreFrom = (words) => {
// Implement this method for wave 4
let scoreMax = 0;
let wordMin = "ZZZZZZZZZZZZZZZZZ";

Choose a reason for hiding this comment

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

Rather than picking an aribtrary "min" word, if our logic gets to the point where we need to distinguich between multiple tied score words, we can pick the first word in the list of values as the word to beat. This can be handy when it's not clear what a good "min" value is. Even in this case, we have to observer that the good min word will be long (since shorter is better) but NOT have a length of exactly ten letters (since that would actually be better than any following word).

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