forked from AdaGold/js-adagrams
-
Notifications
You must be signed in to change notification settings - Fork 50
Yasmin-Leaves #31
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
YasminM11
wants to merge
5
commits into
Ada-C12:master
Choose a base branch
from
YasminM11:master
base: master
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
Yasmin-Leaves #31
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
992caaa
Returns an array of ten strings, randomly drawn from a pool of letter…
YasminM11 87abce8
add usesAvailableLetters function
YasminM11 cbe56e9
added scoreWord function, all tests are passing
YasminM11 db8d9ca
fixed indentation
YasminM11 d59f7e2
changed double quotes to single quotes
YasminM11 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,8 +1,85 @@ | ||
const Adagrams = { | ||
drawLetters() { | ||
// Implement this method for wave 1 | ||
const poolOfLetter = { | ||
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 avaLetters = []; | ||
for (let letter in poolOfLetter) { | ||
for (let i = 0; i < poolOfLetter[letter]; i++) { | ||
avaLetters.push(letter); | ||
} | ||
}; | ||
|
||
let handOfLetters =[]; | ||
for (let i = 0; i < 10; i++) { | ||
let index = Math.floor(Math.random() * avaLetters.length) | ||
let randomLetter = avaLetters[index]; | ||
// remove the randomLetter from avaLetters array | ||
avaLetters.splice(index, 1); | ||
handOfLetters.push(randomLetter); | ||
}; | ||
|
||
return handOfLetters; | ||
}, | ||
// # wave2 code | ||
usesAvailableLetters(input, lettersInHand) { | ||
let userWord = input.toUpperCase(); | ||
for (let letter of userWord) { | ||
if (lettersInHand.includes(letter)) { | ||
lettersInHand.splice(lettersInHand.indexOf(letter), 1); | ||
} else { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}, | ||
|
||
// #Wave_3 | ||
scoreWord(word) { | ||
if (word.length == 0) { | ||
return 0; | ||
} | ||
const onePointLetter = ['A', 'E', 'I', 'O', 'U', 'L', 'N', 'R', 'S', 'T']; | ||
const twoPointLetter = ['D', 'G']; | ||
const threePointLetter = ['B', 'C', 'M', 'P']; | ||
const fourPointLetter = ['F', 'H', 'V', 'W', 'Y']; | ||
const fivePointLetter = ['K']; | ||
const eightPointLetter = ['J', 'X']; | ||
const tenPointLetter = ['Q', 'Z']; | ||
|
||
let letters = word.toUpperCase().split(''); | ||
const scores = letters.map((letter) => { | ||
let letterScore = 0; | ||
|
||
if (onePointLetter.includes(letter)) { | ||
letterScore += 1; | ||
} else if (twoPointLetter.includes(letter)) { | ||
letterScore += 2; | ||
} else if (threePointLetter.includes(letter)) { | ||
letterScore += 3; | ||
} else if (fourPointLetter.includes(letter)) { | ||
letterScore += 4; | ||
} else if (fivePointLetter.includes(letter)) { | ||
letterScore += 5; | ||
Comment on lines
+45
to
+66
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. This ends up being pretty difficult to read and check. I would suggest using a JS Object in the form of hashStyleScores = {
'A': 1,
'B': 4
} This format makes it easy to find and change each letter, and means that scoring a single letter is a one-line operation! |
||
} else if (eightPointLetter.includes(letter)) { | ||
letterScore += 8; | ||
} else if (tenPointLetter.includes(letter)) { | ||
letterScore += 10; | ||
} | ||
return letterScore; | ||
}); | ||
|
||
|
||
let totalScore = scores.reduce((total, num) => total + num); | ||
if (letters.length >= 7) { | ||
totalScore += 8; | ||
} | ||
return totalScore; | ||
} | ||
}; | ||
|
||
// Do not remove this line or your tests will break! | ||
export default Adagrams; | ||
export default Adagrams; |
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.
splice
returns the deleted elements, so you can smoosh these lines together like so:handOfLetters.push( avaLetters.splice(index, 1) );