forked from AdaGold/js-adagrams
-
Notifications
You must be signed in to change notification settings - Fork 20
Ocelot- Anna Du #18
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
Open
anjing0921
wants to merge
20
commits into
ada-ac2:main
Choose a base branch
from
anjing0921:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Ocelot- Anna Du #18
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
049a825
initialize the letterPool and scoreChart
anjing0921 b58f43c
copy the LetterPool pick a random letter from pool
anjing0921 208f89a
delete letter when the value is 0
anjing0921 5042165
add more comment wave 1 done
anjing0921 4d53f0c
set objects
anjing0921 717afe0
set letters of letterInHand as key value.
anjing0921 e79ca83
add check input letter in lettersInHandFreq
anjing0921 0016df6
check the length of word
anjing0921 ff1e5a1
get the score of word's length less than 7
anjing0921 38f6fd1
get score of word length >=7
anjing0921 decb291
complete test word score give empty string return 0
anjing0921 0bdceaf
add to UpperCase
anjing0921 9ab4907
delete the skip
anjing0921 f859337
add comments
anjing0921 8be20b7
modify let to const
anjing0921 ca1ca6c
check each word's score
anjing0921 05e10b0
compare the score with highestScore
anjing0921 a8ffb25
add assert
anjing0921 427f75c
wave 4 done
anjing0921 421537f
add comments
anjing0921 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,151 @@ | ||
| const letterPool = { | ||
| 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, | ||
| }; | ||
|
|
||
| const scoreChart ={ | ||
| 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, | ||
|
|
||
| }; | ||
|
|
||
| export const drawLetters = () => { | ||
| // Implement this method for wave 1 | ||
| // initial drawLetters, cloneLetterPool, letters | ||
| const drawLetters = []; | ||
| let cloneLetterPool = {...letterPool}; | ||
| let letters = Object.keys(cloneLetterPool); | ||
|
|
||
| // for loop 10 times | ||
| for (let i=0;i<10;++i){ | ||
| // get random letter in the pool | ||
| let randomLetter = letters[Math.floor(Math.random()*letters.length)]; | ||
| // check the value of letter in the pool | ||
| if (cloneLetterPool[randomLetter]>0){ | ||
| cloneLetterPool[randomLetter]--; | ||
| drawLetters.push(randomLetter); | ||
| }; | ||
| }; | ||
| return drawLetters; | ||
| }; | ||
|
|
||
| export const usesAvailableLetters = (input, lettersInHand) => { | ||
| // Implement this method for wave 2 | ||
| }; | ||
| // set new object | ||
| let lettersInHandFreq = {}; | ||
| // count letter frequency | ||
| for (let letter of lettersInHand) { | ||
| if (letter in lettersInHandFreq) { | ||
| lettersInHandFreq[letter] += 1; | ||
| }else{ | ||
| lettersInHandFreq[letter] = 1; | ||
| } | ||
| }; | ||
|
|
||
| // check input letter | ||
| for (let cha of input) { | ||
|
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 might call this something like |
||
| if (cha in lettersInHandFreq) { | ||
| if (lettersInHandFreq[cha] >= 1) { | ||
| lettersInHandFreq[cha] -= 1; | ||
| } else{ | ||
| return false; | ||
| } | ||
| } else { | ||
| return false; | ||
| }; | ||
| } | ||
| return true; | ||
| } | ||
| export const scoreWord = (word) => { | ||
| // Implement this method for wave 3 | ||
| // initial wordLength and score | ||
| let wordLength = word.length; | ||
| let score = 0; | ||
| // get the score for wordLength < 7 | ||
| if (wordLength < 7) { | ||
| for(let cha of word.toUpperCase()) { | ||
| let chaScore = scoreChart[cha]; | ||
| score += chaScore; | ||
| } | ||
| return score; | ||
| } else{ | ||
| // get the score for wordLength >= 7 | ||
| score = 8; | ||
| for(let cha of word.toUpperCase()) { | ||
| let chaScore = scoreChart[cha]; | ||
| score += chaScore; | ||
| } | ||
| return score; | ||
| } | ||
|
|
||
| }; | ||
|
|
||
| export const highestScoreFrom = (words) => { | ||
| // Implement this method for wave 4 | ||
| // Initial hightestScore and winningWord | ||
| let highestScore = 0; | ||
| let winningWord = ""; | ||
| //iterate each word and get the score | ||
| words.forEach((word) => { | ||
| let score = scoreWord(word); | ||
| // if the score more than highestScore sign on the new data | ||
| if (score > highestScore){ | ||
| highestScore = score; | ||
| winningWord = word; | ||
| } else if (score === highestScore) { | ||
| //if the scores are same, choose the word, which is length is 10 | ||
| if (word.length === 10 && winningWord.length != 10) { | ||
| winningWord = word; | ||
| // //if the scores are same, choose the length is smaller. | ||
| } else if (word.length < winningWord.length && winningWord.length != 10){ | ||
| winningWord = word; | ||
| } | ||
| } | ||
| }); | ||
| const winner = {word: winningWord, score:highestScore}; | ||
| return winner; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nice use of spread syntax