Skip to content

AC2-Ocelots - Catherine Bandarchuk - JS-AdaGrams - #7

Open
CatherineBandarchuk wants to merge 3 commits into
ada-ac2:mainfrom
CatherineBandarchuk:main
Open

AC2-Ocelots - Catherine Bandarchuk - JS-AdaGrams#7
CatherineBandarchuk wants to merge 3 commits into
ada-ac2:mainfrom
CatherineBandarchuk:main

Conversation

@CatherineBandarchuk

Copy link
Copy Markdown

Didn't do optional wave 5.

@kelsey-steven-ada kelsey-steven-ada left a comment

Copy link
Copy Markdown

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 thread src/adagrams.js
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"]);
}
}

Copy link
Copy Markdown

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.

Comment thread src/adagrams.js
@@ -1,15 +1,136 @@
export const drawLetters = () => {
// Implement this method for wave 1
const POOL_LETTERS_DICT = [

Copy link
Copy Markdown

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 thread src/adagrams.js
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;

Copy link
Copy Markdown

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 thread src/adagrams.js
Comment on lines +40 to +42
let randomIndexLetter = Math.floor(
Math.random() * availableListOfLetters.length
);

Copy link
Copy Markdown

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);

Comment thread src/adagrams.js
let randomIndexLetter = Math.floor(
Math.random() * availableListOfLetters.length
);
let oneLetter = availableListOfLetters[randomIndexLetter];

Copy link
Copy Markdown

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 thread src/adagrams.js
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);
}
}

Copy link
Copy Markdown

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.

Comment thread src/adagrams.js
export const scoreWord = (word) => {
// Implement this method for wave 3
let user_points = 0;
const SCORE_CHART = [

Copy link
Copy Markdown

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 thread src/adagrams.js
Comment on lines +106 to +109
for (let letterW of word) {
const letterObj = SCORE_CHART.find(({ letter }) => letter === letterW);
user_points += letterObj.value;
}

Copy link
Copy Markdown

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;
  }
}

Comment thread src/adagrams.js
if (word.length >= 7) {
user_points = 8;
}
for (let letterW of word) {

Copy link
Copy Markdown

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.

Comment thread src/adagrams.js
let usersScore = 0;
let maxScore = 0;
let maxWord = "";
for (let word of words) {

Copy link
Copy Markdown

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