-
Notifications
You must be signed in to change notification settings - Fork 112
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
base: main
Are you sure you want to change the base?
Changes from 19 commits
c741f96
4880f36
29b6ebb
7b3c719
2934cd0
af5d6d0
1b5f735
a836570
075cca8
9d4dd59
a59e847
09fd913
ab2fbd4
47ee11c
7d77e1c
76e0931
1407b18
2ec2f47
802f984
f0692cf
52f0778
a02d19d
f613888
b666e82
c1e7ada
6d8a769
50d4bad
944c72a
22307c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"cSpell.enableFiletypes": [ | ||
"!javascript", | ||
"!markdown" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,172 @@ | ||
export const drawLetters = () => { | ||
// Implement this method for wave 1 | ||
const scoreChart = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we'd want to rename this something like |
||
A: 9, | ||
B: 2, | ||
C: 2, | ||
D: 4, | ||
E: 12, | ||
F: 2, | ||
G: 3, | ||
H: 2, | ||
I: 9, | ||
J: 1, | ||
K: 1, | ||
L: 4, | ||
M: 2, | ||
N: 6, | ||
O: 8, | ||
P: 2, | ||
Q: 1, | ||
R: 6, | ||
S: 4, | ||
T: 6, | ||
U: 4, | ||
V: 2, | ||
W: 2, | ||
X: 1, | ||
Y: 2, | ||
Z: 1, | ||
}; | ||
|
||
let letters = []; | ||
|
||
for (const [letter, inputLetterFreq] of Object.entries(scoreChart)) { | ||
for (let i = 0; i < inputLetterFreq; i++) { | ||
letters.push(letter); | ||
} | ||
}; | ||
// 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); | ||
Comment on lines
+39
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 If we create an empty list
At the end of our loop we'll have a full |
||
}; | ||
|
||
export const usesAvailableLetters = (input, lettersInHand) => { | ||
// Implement this method for wave 2 | ||
let inputLetterFreq = {}; | ||
|
||
for (const letter of input) { | ||
if (letter.toUpperCase() in inputLetterFreq) { | ||
inputLetterFreq[letter.toUpperCase()] += 1; | ||
} else { | ||
inputLetterFreq[letter.toUpperCase()] = 1; | ||
} | ||
}; | ||
|
||
let lettersInHandFreq = {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice use of frequency maps =] |
||
|
||
for (const letter of lettersInHand) { | ||
if (letter.toUpperCase() in lettersInHandFreq) { | ||
lettersInHandFreq[letter.toUpperCase()] += 1; | ||
} else { | ||
lettersInHandFreq[letter.toUpperCase()] = 1; | ||
} | ||
}; | ||
|
||
for (const letter of input) { | ||
/* If the letter does not exist in the `lettersInHandFreq` or the `input` letter | ||
frequency is greater than `lettersInHand`'s frequency, return false. Otherwise, | ||
return true. */ | ||
if (typeof(lettersInHandFreq[letter.toUpperCase()]) === 'undefined' || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it might be worth making a variable to hold the uppercased letter before the if-statement, so we only need to call |
||
inputLetterFreq[letter.toUpperCase()] > lettersInHandFreq[letter | ||
.toUpperCase()]) { | ||
Comment on lines
+76
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice splitting this if-statement across lines for readability! |
||
return false; | ||
} | ||
} | ||
return true; | ||
}; | ||
|
||
export const scoreWord = (word) => { | ||
// Implement this method for wave 3 | ||
const scoreChart = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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! |
||
A: 1, | ||
B: 3, | ||
C: 3, | ||
D: 2, | ||
E: 1, | ||
F: 4, | ||
G: 2, | ||
H: 4, | ||
I: 1, | ||
J: 8, | ||
K: 5, | ||
L: 1, | ||
M: 3, | ||
N: 1, | ||
O: 1, | ||
P: 3, | ||
Q: 10, | ||
R: 1, | ||
S: 1, | ||
T: 1, | ||
U: 1, | ||
V: 4, | ||
W: 4, | ||
X: 8, | ||
Y: 4, | ||
Z: 10 | ||
}; | ||
|
||
let score = 0; | ||
|
||
for (const letter of word) { | ||
if (letter.toUpperCase() in scoreChart) { | ||
score += scoreChart[letter.toUpperCase()]; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Neat implementation of feedback from the python version! |
||
if (word.length >= 7 && word.length <= 10) { | ||
score += 8; | ||
} | ||
return score; | ||
}; | ||
|
||
export const highestScoreFrom = (words) => { | ||
// Implement this method for wave 1 | ||
}; | ||
// tests for this loop run eternally in vscode | ||
/* | ||
1) For loop through each word in `words` | ||
|
||
2) An string that represents the word and a number representing the score is pushed to `word_scores` | ||
|
||
3) Initalize a variable `max_score` where the first object's score is the max | ||
value. Initialize an array called `ties` that hold | ||
|
||
4) Loop through `word_scores` from the end to the beginnning with a step of -2. | ||
|
||
5) If the `word_score[i]` is is greater than or equal to the `max_score`, reassign `max_score` to `word_scores[i]`. | ||
|
||
6) Return an object. The first property has the key word, the value is the index position of `max_score` - 1. The second property has a the key of score and a value of `max_score`. | ||
*/ | ||
|
||
// // words_scores can be like this = [{X: 8}, {XX: 16}, {XXX: 24}, {XXXX: 32}] | ||
// // or maybe this = ['X', 8, 'XX', 16, 'XXX', 24, 'XXXX', 32] | ||
|
||
const word_scores = []; | ||
|
||
for (let i = 0; i < words.length; i++) { | ||
// word_scores.push({[words[i]]: scoreWord(words[i])}) | ||
word_scores.push(words[i]) | ||
word_scores.push(scoreWord(words[i])) | ||
} | ||
|
||
let max_score = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
// something is up with my condition here | ||
for (let i = word_scores.length; i < word_scores.length; i -= 2) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now Since javascript arrays also uses 0-based indexing, we would want to start |
||
if (word_scores[i + 1] > max_score) { | ||
max_score = word_scores[i + 1]; | ||
} | ||
} | ||
|
||
return { | ||
word: word_scores.indexOf(max_score) - 1, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
score: max_score | ||
}; | ||
}; |
There was a problem hiding this comment.
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