Skip to content

Branches, Kristy #50

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 2 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
88 changes: 87 additions & 1 deletion src/adagrams.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,93 @@
const allLetters = ["A", "A", "A", "A", "A", "A", "A", "A", "A", "B", "B", "C", "C", "D", "D", "D", "D", "E", "E", "E",
"E", "E", "E", "E", "E", "E", "E", "E", "E", "F", "F", "G", "G", "G", "H", "H", "I", "I", "I",
"I", "I", "I", "I", "I", "I", "J", "K", "L", "L", "L", "L", "M", "M", "N", "N", "N", "N", "N", "N",
"O", "O", "O", "O", "O", "O", "O", "O", "P", "P", "Q", "R", "R", "R", "R", "R", "R", "S", "S", "S", "S",
"T", "T", "T", "T", "T", "T", "U", "U", "U", "U", "V", "V", "W", "W", "X", "Y", "Y", "Z" ]

const Adagrams = {

drawLetters() {
// Implement this method for wave 1
let letters = allLetters
let hand = [];
for (let i = 0; i < 10; i ++) {
let index = Math.floor(Math.random() * letters.length)
let rand = letters[index];
hand.push(rand);
letters.splice(index, 1);
}
return hand;
},

usesAvailableLetters(word, drawn) {
if (word.length > 10) {
return false;
}

let x = true;
let j = 0;
let i = 0;

while (x === true && j < word.length) {
if (drawn.includes(word[i])) {
let x = drawn.indexOf(word[i])
drawn.splice(x, 1);
i ++;
j ++;
} else {
x = false;
}
}
return x;
},

scoreWord(word) {
let score = 0;
const correctWord = word.toUpperCase()
if (correctWord.length >= 7) {
score += 8;
}

for (let i = 0; i < correctWord.length; i ++) {

if(["A", "E", "I", "O", "U", "L", "N", "R", "S", "T"].includes(correctWord[i])) {
score += 1;
} else if(["D", "G"].includes(correctWord[i])) {
score += 2;
} else if(["B", "C", "M", "P"].includes(correctWord[i])) {
score += 3;
} else if(["F", "H", "V", "W", "Y"].includes(correctWord[i])) {
score += 4;
} else if(["K"].includes(correctWord[i])) {
score += 5;
} else if(["J", "X"].includes(correctWord[i])) {
score += 8;
} else if(["Q", "Z"].includes(correctWord[i])) {
score += 10;
}
}
return score;
},

highestScoreFrom(array) {

let highest = {
length: array[0].length,
word: array[0],
score: this.scoreWord(array[0])
};
const that = this
array.forEach(function(word) {
let currentScore = that.scoreWord(word);
if (currentScore >= highest.score && highest.length != 10){
highest.word = word;
highest.score = currentScore;
highest.length = word.length;
};
});

delete highest.length;
return highest;
}
};

// Do not remove this line or your tests will break!
Expand Down
2 changes: 1 addition & 1 deletion test/adagrams.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('Adagrams', () => {
});
});

describe.skip('highestScoreFrom', () => {
describe('highestScoreFrom', () => {
it('returns a hash that contains the word and score of best word in an array', () => {
const words = ['X', 'XX', 'XXX', 'XXXX'];
const correct = { word: 'XXXX', score: Adagrams.scoreWord('XXXX') };
Expand Down