Skip to content

Conversation

bukunmig
Copy link

@bukunmig bukunmig commented Dec 9, 2022

  • Reviewed tests and can't see exceptions. Not sure why test is failing.

Copy link
Contributor

@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.

Your submitted waves look good. Keep the algorithmic complexity in mind =, since just like python, many built-in JS array methods are hiding loops that we need to be aware of and may want to avoid when we're already within another loop. Please be sure to ping me when you've re-submitted with the revisions for the other waves so that I can review those as well.


it("returns a score of 0 if given an empty input", () => {
throw "Complete test";
expectScores ({
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

const correct = { word: "XXXX", score: scoreWord("XXXX") };

throw "Complete test by adding an assertion";
expect(highestScoreFrom(words)).toEqual(correct);
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

let availableLetters = [];
let hand = [];

for (const [key, value] of Object.entries(letterPool)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using names more descriptive of what the key and value represent, such as letter and count.

src/adagrams.js Outdated
Comment on lines 74 to 76
let letter = availableLetters[Math.floor(Math.random() * availableLetters.length)];
hand.push(letter);
let index = availableLetters.indexOf(letter);
Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively, we could organize it this way and avoid needing to find the index

    let index = Math.floor(Math.random() * availableLetters.length);
    let letter = availableLetters[index];
    hand.push(letter);

let letter = availableLetters[Math.floor(Math.random() * availableLetters.length)];
hand.push(letter);
let index = availableLetters.indexOf(letter);
availableLetters.splice(index, 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that this has the same time costs as remove in python. That is, anything after the data that was removed needs to be shifted to fill the gap in the array, resulting in a O(n) time complexity with respect to the list length. Since we're working with fixed lenths (26 letters a certain number of times each, and a 10 letter hand), we dont need to worry too much about the absolute performance, but in general we want to find approaches that don't perform linear complexity operations within a loop.

src/adagrams.js Outdated
export const usesAvailableLetters = (input, lettersInHand) => {
// Implement this method for wave 2
};
// wave 2
Copy link
Contributor

Choose a reason for hiding this comment

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

👀 Let me know when you've completed your rework on wave 2

src/adagrams.js Outdated
export const highestScoreFrom = (words) => {
// Implement this method for wave 4
};
// TODO: REDO Simple option
Copy link
Contributor

Choose a reason for hiding this comment

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

👀 Let me know when you've completed your re-work on wave 4

// wave 2


export const scoreWord = (word) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@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.

Thanks for updating your submission. Looks good!

// - Returns `true` if every letter in the `input` word is available (in the right quantities) in the `lettersInHand`
// - Returns `false` if not; if there is a letter in `input` that is not present in the `lettersInHand` or has too much of compared to the `lettersInHand`

lettersInHand = [...lettersInHand];
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 Since we're splicing values out of the hand, we need this copy so that we don't destroy the passed in hand.

Comment on lines +94 to +96
if(lettersInHand.includes(letter)) {
let indexLettersInHand = lettersInHand.indexOf(letter);
lettersInHand.splice(indexLettersInHand, 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Notice that we can use the result from indexOf itself to tell us whether the value is in the array, since it returns -1 if it is not. So we could wrrite this as

    const indexLettersInHand = lettersInHand.indexOf(letter);
    if (indexLettersInHand !== -1) {
      lettersInHand.splice(indexLettersInHand, 1);

Copy link
Contributor

Choose a reason for hiding this comment

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

This approcah (removing the values from from the hand copy as we use them) is going to be a quadratic O(n^2) approach (since the splice, like a remove, must shift everything else forward as things get removes). We could still think about building a frequency table of letters to determine whether the word can be made with the hand in linear time.

winningWordAndScore ['score'] = value;
};

if (value === winningWordAndScore['score'] && winningWordAndScore['word'].length < 10) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The tie breaker conditions can be an else if, since if the new score beat the old score outright, there's no need to check any of the tie breaking code.

score: Object.values(wordsAndScores)[0]
};

for (const[key, value] of Object.entries(wordsAndScores)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using more descriptive names for the key and value (maybe word and score) so we don't have to remember that the key is the word and the value is the score.

// Implement this method for wave 3
// wave 3
let score = 0;
for (let letter of word) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer to use const for the loop control variable (letter).

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