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

Branches - Angele #35

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
97 changes: 96 additions & 1 deletion src/adagrams.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,103 @@
const Adagrams = {
letterInfo: {
"A": {count: 9, points: 1},
"B": {count: 2, points: 3},
"C": {count: 2, points: 3},
"D": {count: 4, points: 2},
"E": {count: 12, points: 1},
"F": {count: 2, points: 4},
"G": {count: 3, points: 2},
"H": {count: 2, points: 4},
"I": {count: 9, points: 1},
"J": {count: 1, points: 8},
"K": {count: 1, points: 5},
"L": {count: 4, points: 1},
"M": {count: 2, points: 3},
"N": {count: 6, points: 1},
"O": {count: 8, points: 1},
"P": {count: 2, points: 3},
"Q": {count: 1, points: 10},
"R": {count: 6, points: 1},
"S": {count: 4, points: 1},
"T": {count: 6, points: 1},
"U": {count: 4, points: 1},
"V": {count: 2, points: 4},
"W": {count: 2, points: 4},
"X": {count: 1, points: 8},
"Y": {count: 2, points: 4},
"Z": {count: 1, points: 10},
},

drawCount: 10,
Copy link

Choose a reason for hiding this comment

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

GREAT DECISION on letterInfo and drawCount!


drawLetters() {
// Implement this method for wave 1
const letterInfo = this.letterInfo;
const letterPool = [];
for (let letter in letterInfo) {
const letterCount = letterInfo[letter].count
for (let i = 0; i < letterCount; i++){
letterPool.push(letter);
}
}
// console.log(letterPool);

const randomIndices = [];

while (randomIndices.length < this.drawCount) {
const randomIndex = Math.floor(Math.random() * letterPool.length);
if (!randomIndices.includes(randomIndex)) {
randomIndices.push(randomIndex);
}
}
Copy link

Choose a reason for hiding this comment

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

Nicely done. If you ever think about refactoring this, I think it might be interesting to refactor this while loop so that: instead of pushing randomIndex into randomIndices until randomIndices has a length of ten, and then mapping overrandomIndices in order to populatedrawnLetters... Consider usingrandomIndicesonletterPoolto populate/push intodrawnLetters` directly

// console.log(`randomIndices: ${randomIndices}`);

const drawnLetters = randomIndices.map((index) => {
return letterPool[index];
});

// console.log(`drawnLetters: ${drawnLetters}`)

return drawnLetters;

},

usesAvailableLetters(input, lettersInHand) {
const handCopy = [...lettersInHand];
Copy link

Choose a reason for hiding this comment

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

Nice syntax here!


const validInputs = input.split('').map((letter) => {
if (handCopy.includes(letter)) {
const letterIndex = handCopy.indexOf(letter);
handCopy.splice(letterIndex,1);
// console.log(`handCopy: ${handCopy}`);
return true;
} else {return false;}
});

return validInputs.includes(false) ? false : true;
},

scoreWord(word) {
const letterInfo = this.letterInfo;
const wordArray = word.toUpperCase().split('');

const letterPoints = wordArray.map(letter => letterInfo[letter]['points']);

console.log(letterPoints);

if (wordArray.length >= 7) {
letterPoints.push(8);
}

const wordPoints = letterPoints.reduce((total, points) => total + points, 0);
Copy link

Choose a reason for hiding this comment

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

I love this reduce!


return wordPoints;


},

};

console.log(Adagrams.usesAvailableLetters('poopies', ['p','o','o','l']));
Copy link

Choose a reason for hiding this comment

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

:P :)


// Do not remove this line or your tests will break!
export default Adagrams;
2 changes: 2 additions & 0 deletions test/adagrams.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,5 @@ describe('Adagrams', () => {
});
});
});