Skip to content

Conversation

@CatherineBandarchuk
Copy link

Didn't do optional wave 5.

Copy link

@kelsey-steven-ada kelsey-steven-ada 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! I’ve added some suggestions, let me know if there's anything I can clarify ^_^

Comment on lines +31 to +36
let availableListOfLetters = [];
for (const letter of POOL_LETTERS_DICT) {
for (let i = 0; i < letter["count"]; ++i) {
availableListOfLetters.push(letter["letter"]);
}
}

Choose a reason for hiding this comment

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

Really nice solution for ensuring we get the desired distribution of letters.

@@ -1,15 +1,136 @@
export const drawLetters = () => {
// Implement this method for wave 1
const POOL_LETTERS_DICT = [

Choose a reason for hiding this comment

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

Great use of a const

Comment on lines +38 to +48
let lettersInHand = [];
for (let i = 0; i < 10; ++i) {
let randomIndexLetter = Math.floor(
Math.random() * availableListOfLetters.length
);
let oneLetter = availableListOfLetters[randomIndexLetter];
availableListOfLetters.splice(randomIndexLetter, 1);
lettersInHand.push(oneLetter);
}

return lettersInHand;

Choose a reason for hiding this comment

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

I like the approach!

Comment on lines +40 to +42
let randomIndexLetter = Math.floor(
Math.random() * availableListOfLetters.length
);

Choose a reason for hiding this comment

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

Unless we're in a system that is really low on memory, I would consider making a new variable to hold the result of the multiplication over indentation.

const randomFloat = Math.random() * availableListOfLetters.length;
const randomIndex = Math.floor(randomFloat);

let randomIndexLetter = Math.floor(
Math.random() * availableListOfLetters.length
);
let oneLetter = availableListOfLetters[randomIndexLetter];

Choose a reason for hiding this comment

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

I suggest using const to declare variables which shouldn't get reassigned within the current scope.

Comment on lines +55 to +61
for (let letter of input) {
const indexOfLetter = lettersInHand.indexOf(letter);
if (indexOfLetter !== -1) {
lettersInHand.splice(indexOfLetter, 1);
checkedWord.push(letter);
}
}

Choose a reason for hiding this comment

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

Nice approach! If we needed to reduce the time complexity of our solution, another approach could be to build a frequency map of our hand then loop over the characters in the input, checking if the character is in our frequency map, and if it is, then check the value to see if there are still tiles left in our hand for that letter.

export const scoreWord = (word) => {
// Implement this method for wave 3
let user_points = 0;
const SCORE_CHART = [

Choose a reason for hiding this comment

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

Since this is a local constant (only has scope in this function), we should use camel case for the naming scoreChart.

Comment on lines +106 to +109
for (let letterW of word) {
const letterObj = SCORE_CHART.find(({ letter }) => letter === letterW);
user_points += letterObj.value;
}

Choose a reason for hiding this comment

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

The array find function is an O(n) operation. If we structured SCORE_CHART as a javascript object where the letters are the keys and the points are the values, you could reduce the time complexity by being able to access the SCORE_CHART's values using the letters of the input word as keys.

const scoreChart = {
  A: 1,
  E: 1,
  I: 1,
...
  X: 8,
  Q: 10,
  Z: 10,
};

for (const letter of word) {
  const letterValue = letterValues[letter];
  if (letterValue != undefined) {
    score += letterValue;
  }
}

if (word.length >= 7) {
user_points = 8;
}
for (let letterW of word) {

Choose a reason for hiding this comment

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

Nice use of a for...of loop.

let usersScore = 0;
let maxScore = 0;
let maxWord = "";
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.

Nice implementation to tie break in a single loop!

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