Skip to content

Branches - Erika #32

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
wants to merge 11 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
84 changes: 82 additions & 2 deletions src/adagrams.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,88 @@
const Adagrams = {

letters: {
"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
},


// Use Fisher-Yates/Knuth Shuffle
shuffler(array) {

Choose a reason for hiding this comment

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

Nice helper! With good documentation!

const length = array.length - 1
for (let i = length; i > 0; i--) {
const j = Math.floor(Math.random() * i);
const temp = array[i];
array[i] = array[j];
array[j] = temp;
}
return array;
},

drawLetters() {

Choose a reason for hiding this comment

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

👍

// Implement this method for wave 1
let letters = this.letters;
const letterSet = [];
for (let element in letters) {
let count = letters[element] + 1;
do {
count -= 1;
letterSet.push(element);
} while (count > 0);
};

let shuffledArr = this.shuffler(letterSet);
return shuffledArr.splice(0, 10)
},
};

usesAvailableLetters(input, lettersInHand) {
for (let element of input) {
if (!lettersInHand.includes(element)) {
return false;
} else {
let index = lettersInHand.indexOf(element);
lettersInHand.splice(index, 1);

Choose a reason for hiding this comment

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

One problem here is that letters in hand will be mutated here. That could lead to side-effects if someone 's anticipating that the original array isn't modified.

}
}
return true;
},

scoreWord(word) {
let string = word.toUpperCase();
const pointSystem = {
1: ["A", "E", "I", "O", "U", "L", "N", "R", "S", "T"],
2: ["D", "G"],
3: ["B", "C", "M", "P"],
4: ["F", "H", "V", "W", "Y"],
5: ["K"],
6: ["J", "X"],
7: ["Q", "Z"]
}

let points = 0;
let length = string.length;
if (length >= 7 && length <= 10) { points += 8 };
for (let letter of string) {

let elementScore =
(pointSystem[1].includes(letter)) ? 1
:(pointSystem[2].includes(letter)) ? 2
:(pointSystem[3].includes(letter)) ? 3
:(pointSystem[4].includes(letter)) ? 4
:(pointSystem[5].includes(letter)) ? 5
:(pointSystem[6].includes(letter)) ? 8
:(pointSystem[7].includes(letter)) ? 10
:points = 0

points += elementScore
}
return points;
}

}


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