Skip to content
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
167 changes: 166 additions & 1 deletion src/adagrams.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,172 @@
// Wave 1 Problem
const Adagrams = {
drawLetters() {
// Implement this method for wave 1
const alphabets = {
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,
x: 1,
y: 2,
z: 1
};
let allLetters = [];
for (let letter in alphabets) {
let quantity = alphabets[letter];
let letters = [];
let i = 0;
while (i < quantity) {
letters.push(letter);
i++;
}
allLetters.push(letters);
}
allLetters = allLetters.flat();

allLetters = shuffle(allLetters);

let yourLetters = [];
let j = 0;
while (j < 10) {
yourLetters.push(allLetters[j]);
j++;
}

return yourLetters;
},

usesAvailableLetters(input, lettersInHand) {
let word = input.toLowerCase().split("");
let sameLetters = shuffle(lettersInHand);

word.forEach(function(letter) {
if (sameLetters.includes(letter)) {
let letterLocation = sameLetters.indexOf(letter);
sameLetters.splice(letterLocation, 1);
} else {
return false;
}
Comment on lines +57 to +66

Choose a reason for hiding this comment

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

I am surprised to realize 2 of the 3 tests still fail when I add the return statement mentioned below. There are several bugs in this code that it'd be good for us to talk about during our 1:1 next week.

});
},

Choose a reason for hiding this comment

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

There should be a return true; before the end of the function. As is the function is not returning anything if it hasn't already returned false.


scoreWord(word) {
let userWord = word.toLowerCase().split("");
let totalScore = 0;
userWord.forEach(function(letter) {
switch (letter) {
case "a":
case "e":
case "i":
case "o":
case "u":
case "l":
case "n":
case "r":
case "s":
case "t":
totalScore += 1;
break;
case "d":
case "g":
totalScore += 2;
break;
case "b":
case "c":
case "m":
case "p":
totalScore += 3;
break;
case "f":
case "h":
case "v":
case "w":
case "y":
totalScore += 4;
break;
case "k":
totalScore += 5;
break;
case "j":
case "x":
totalScore += 8;
break;
case "q":
case "z":
totalScore += 10;
break;
default:
totalScore = 0;
break;
}
});

if (userWord.length > 6) {
totalScore += 8;
}

return totalScore;
},

// # Wave 4 Problem
highestScoreFrom(words) {
let winningWord = {};

let maxWordScore = 0;
let maxWord = "";
winningWordLetterCount = 0;

Choose a reason for hiding this comment

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

needs a let


words.forEach(function(word) {
if (scoreWord(word) > maxWordScore) {

Choose a reason for hiding this comment

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

This function doesn't successfully run. Each call to the scoreWord function should be called with Adagrams.scoreWord

maxWordScore = scoreWord(word);
maxWord = word;
winningWordLetterCount = word.length;
} else if (scoreWord(word) == maxWordScore) {
if (word.length == 10) {
maxWordScore = scoreWord(word);
maxWord = word;
winningWordLetterCount = word.length;
} else if (word.length < winningWordLetterCount) {
maxWordScore = scoreWord(word);
maxWord = word;
winningWordLetterCount = word.length;
}
}
});

winningWord = {
word: maxWord,
score: maxWordScore
};
return winningWord;
}
};
const shuffle = function(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * i);
const temp = array[i];
array[i] = array[j];
array[j] = temp;
}
let shuffledArray = array; //.sort(() => Math.random() - 0.5);
return shuffledArray;
};

// Do not remove this line or your tests will break!
Expand Down