-
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
Sharks - Jeannie #111
base: main
Are you sure you want to change the base?
Sharks - Jeannie #111
Changes from all commits
39df8b0
8f12346
3a02057
ecaab76
61668f7
d3460f3
28758b1
a0d2ac7
73e148c
634578c
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 | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,15 +1,157 @@ | ||||||||||||||||
|
||||||||||||||||
const score_chart = { | ||||||||||||||||
'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 | ||||||||||||||||
let LETTER_POOL = { | ||||||||||||||||
'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 | ||||||||||||||||
}; | ||||||||||||||||
// create a string that holds all the avaliable letters - including probability | ||||||||||||||||
let playerHand = []; | ||||||||||||||||
let alphabet = ""; | ||||||||||||||||
for (const [key, value] of Object.entries(LETTER_POOL)) { | ||||||||||||||||
alphabet += key.repeat(value); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
// create 10 letters for the player hand | ||||||||||||||||
// subtract the letter from avaliable letters | ||||||||||||||||
while (playerHand.length < 10) { | ||||||||||||||||
let randomCharacter = alphabet[Math.floor(Math.random() * alphabet.length)]; | ||||||||||||||||
|
||||||||||||||||
if (LETTER_POOL[randomCharacter] === 0) { | ||||||||||||||||
continue; | ||||||||||||||||
} else { | ||||||||||||||||
playerHand.push(randomCharacter); | ||||||||||||||||
LETTER_POOL[randomCharacter] -= 1; | ||||||||||||||||
alphabet.replace(randomCharacter, ''); | ||||||||||||||||
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. love this idea! One thing I would suggest is turning Each time we call |
||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
return playerHand; | ||||||||||||||||
}; | ||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
export const usesAvailableLetters = (input, lettersInHand) => { | ||||||||||||||||
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. 👍 very interesting approach! |
||||||||||||||||
// Implement this method for wave 2 | ||||||||||||||||
//function returns True if all letters in input are in lettersInHand | ||||||||||||||||
|
||||||||||||||||
let listOfLetters = lettersInHand.slice(); | ||||||||||||||||
let yourString = input.toUpperCase(); | ||||||||||||||||
let boolSet = new Set(); | ||||||||||||||||
//if letter is in lettersInHand, true is added to the set | ||||||||||||||||
for (const char of yourString) { | ||||||||||||||||
if (listOfLetters.includes(char)) { | ||||||||||||||||
boolSet.add(true); | ||||||||||||||||
const index = listOfLetters.indexOf(char); | ||||||||||||||||
listOfLetters.splice(index, 1); | ||||||||||||||||
// if letter is NOT in lettersInHand, false is added to the set | ||||||||||||||||
} else { | ||||||||||||||||
boolSet.add(false); | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
// determine if there is invalid letter or not by checking if false exist | ||||||||||||||||
if (boolSet.has(false)) { | ||||||||||||||||
return false; | ||||||||||||||||
} else { | ||||||||||||||||
return true | ||||||||||||||||
} | ||||||||||||||||
}; | ||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
export const scoreWord = (word) => { | ||||||||||||||||
// Implement this method for wave 3 | ||||||||||||||||
//calculates each score for each letter | ||||||||||||||||
let score = 0; | ||||||||||||||||
|
||||||||||||||||
for (const letter of word) { | ||||||||||||||||
score += score_chart[letter.toUpperCase()] | ||||||||||||||||
} if (word.length >= 7) { | ||||||||||||||||
score += 8; | ||||||||||||||||
} | ||||||||||||||||
Comment on lines
+117
to
+119
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 standard practice is to have the if statement start on its own line. I only ever see a conditional on the same line as a closing curly brace is with
Suggested change
|
||||||||||||||||
return score; | ||||||||||||||||
}; | ||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
export const highestScoreFrom = (words) => { | ||||||||||||||||
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. 👍 |
||||||||||||||||
// Implement this method for wave 1 | ||||||||||||||||
|
||||||||||||||||
let score_list = []; | ||||||||||||||||
let max_score = 0; | ||||||||||||||||
let winning_word = ""; | ||||||||||||||||
Comment on lines
+126
to
+128
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.
Suggested change
|
||||||||||||||||
for (let i = 0; i < words.length; i++) { | ||||||||||||||||
let score = scoreWord(words[i]); | ||||||||||||||||
let results = {}; | ||||||||||||||||
results["score"] = score; | ||||||||||||||||
results["word"] = words[i]; | ||||||||||||||||
score_list.push(results); | ||||||||||||||||
|
||||||||||||||||
if (score > max_score) { | ||||||||||||||||
max_score = score; | ||||||||||||||||
winning_word = words[i]; | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
let winner = { "word": winning_word, "score": max_score }; | ||||||||||||||||
|
||||||||||||||||
for (let item of score_list) { | ||||||||||||||||
if (item["score"] === max_score && item["word"].length === 10) { | ||||||||||||||||
winner = item; | ||||||||||||||||
return winner; | ||||||||||||||||
} else if (item["score"] === max_score && item["word"].length < winning_word.length) { | ||||||||||||||||
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.
Suggested change
|
||||||||||||||||
winner = item; | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
return winner; | ||||||||||||||||
}; | ||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
|
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.
oop careful! use camel case in JavaScript: