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

Esther Annorzie - Sea Turtles #97

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

Conversation

estherannorzie
Copy link

Finished wave 1-3

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.

Good work overall, Esther! I've left some comments and suggestions, please take a look when you can and let me know if there's anything I can clarify =]

src/adagrams.js Outdated
Comment on lines 161 to 162
// something is up with my condition here
for (let i = word_scores.length; i < word_scores.length; i -= 2) {

Choose a reason for hiding this comment

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

Right now i starts at word_scores.length, and our loop checks if i < word_scores.length to decide if we should leave the loop. Since we decrement i by 2 each iteration, i is never greater than word_scores.length, so we never leave the loop. Since the last index we want to hit is 1, if we change the condition statement to ensure we stop at 1, we'll leave the loop as expected.

Since javascript arrays also uses 0-based indexing, we would want to start i at word_scores.length - 1 since it would be the last index.

src/adagrams.js Outdated
}

return {
word: word_scores.indexOf(max_score) - 1,

Choose a reason for hiding this comment

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

.indexOf(max_score) will return us the first word it finds in the list word_scores with the score max_score, even if by our tie breaking rules there might be a shorter string with the same score later in the list we would want to return.

src/adagrams.js Outdated
word_scores.push(scoreWord(words[i]))
}

let max_score = 0;

Choose a reason for hiding this comment

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

So that we can break ties between words with the same score, we might also want to create a list variable that we fill with all the words with a score of max_score.

Comment on lines +39 to +48
// not able to create a shuffling algo myself
// Fisher-Yates shuffle algorithm
// https://masteringjs.io/tutorials/fundamentals/shuffle#:~:text=To%20properly%20shuffle%20an%20array%20in%20JavaScript%2C%20use,random%20element%20in%20the%20array%20as%20shown%20below.
for (let i = letters.length - 1; i >= 1; i--) {
let j = Math.floor(Math.random() * (i + 1));
let temp = letters[j];
letters[j] = letters[i];
letters[i] = temp;
};
return letters.slice(0, 10);

Choose a reason for hiding this comment

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

Creating a proper shuffling algorithm can be a significant problem to solve. We could use the letters array in another approach to create a hand.

If we create an empty list hand, we could fill it by looping 10 times and in each iteration:

  1. create a random number between 0 and the last index of the letters array
  2. Get the letter at our random index from the letter list
  3. Push that letter onto our hand array
  4. Use something like splice to remove the letter at our random index from the letter array so the letter can't be used twice

At the end of our loop we'll have a full hand array and can return it!

Comment on lines +53 to +69
let inputLetterFreq = {};
for (const letter of input) {
if (letter.toUpperCase() in inputLetterFreq) {
inputLetterFreq[letter.toUpperCase()] += 1;
} else {
inputLetterFreq[letter.toUpperCase()] = 1;
}
};

let lettersInHandFreq = {};
for (const letter of lettersInHand) {
if (letter.toUpperCase() in lettersInHandFreq) {
lettersInHandFreq[letter.toUpperCase()] += 1;
} else {
lettersInHandFreq[letter.toUpperCase()] = 1;
}
};

Choose a reason for hiding this comment

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

We perform similar operations to create frequency maps for input and lettersInHand, this would be a great candidate for a helper function that takes in a string and returns a frequency map of the letters.

src/adagrams.js Outdated
@@ -1,15 +1,177 @@
export const drawLetters = () => {
// Implement this method for wave 1
const scoreChart = {

Choose a reason for hiding this comment

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

I think we'd want to rename this something like letterPool or availableLetters to better reflect what it holds.

src/adagrams.js Outdated
};

export const scoreWord = (word) => {
// Implement this method for wave 3
const scoreChart = {

Choose a reason for hiding this comment

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

Nice keeping the scoring and available letter objects inside the functions where they're used!

src/adagrams.js Outdated
Comment on lines 116 to 120
for (const letter of word) {
if (letter.toUpperCase() in scoreChart) {
score += scoreChart[letter.toUpperCase()];
}
}

Choose a reason for hiding this comment

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

Neat implementation of feedback from the python version!

@@ -145,7 +146,8 @@ describe("Adagrams", () => {
const words = ["XXX", "XXXX", "X", "XX"];
const correct = { word: "XXXX", score: scoreWord("XXXX") };

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

Choose a reason for hiding this comment

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

👍

@@ -0,0 +1,6 @@
{

Choose a reason for hiding this comment

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

This looks like a workspace specific settings file. If we see unexpected new files added to a PR, we usually want to double check if they're necessary and remove them from being tracked by git if not. It's not something we need to worry about for our projects, but it can come up when working on a shared code base.

If a file is not already being tracked by git we can list it in the .gitignore file and git will know never to track it, but if git is already tracking a file (like this one), telling it to stop and removing it from tracking takes a step or two. This stack overflow talks about how you can remove a file from being tracked if you're interested: https://stackoverflow.com/questions/1274057/how-can-i-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitign

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