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

Earth - Ana #51

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 69 additions & 2 deletions src/adagrams.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,75 @@
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 letterScore = {
A: 1, E: 1, I: 1, O: 1, U: 1, L: 1, N: 1, R: 1, S: 1, T: 1,
D: 2, G: 2,
B: 3, C: 3, M: 3, P: 3,
F: 4, H: 4, V: 4, W: 4, Y: 4,
K: 5,
J: 8, X: 8,
Q: 10, Z: 10
};

const Adagrams = {

// Wave one

drawLetters() {
// Implement this method for wave 1
const letterPoolArray = [];

for(const letter in letterPool){
for(let i = 0; i < letterPool[letter]; i++) {
letterPoolArray.push(letter);
}
}

const hand = [];

for(let i = 0; i < 10; i++){
const randomLetters = letterPoolArray[Math.floor(Math.random() * letterPoolArray.length)];
hand.push(randomLetters);
}
return hand;
},
};

// Wave two
usesAvailableLetters(input,lettersInHand ){
let validWord = true;
let userWord = input.toUpperCase().split('');

Choose a reason for hiding this comment

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

This is the one example I see where let is used when const could've been used instead, so great job with that overall!


userWord.forEach((char) => {
let index = lettersInHand.indexOf(char);

if(index === -1) {
validWord = false;
} else {
lettersInHand.splice(index,1)
}
})
return validWord;
},

Choose a reason for hiding this comment

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

Minor thing: This should be indented two spaces less


// Wave Three

scoreWord(word) {
let score = 0
for(const letter of word.toUpperCase().split('')){
score += letterScore[letter];
}
if (word.length >= 7) {
score += 8;
}
return score;
},
//Wave 4

// highestScoreFrom(words)


}

// Do not remove this line or your tests will break!
export default Adagrams;