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

Leaves - Cloudy #47

Open
wants to merge 8 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
18 changes: 18 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"workbench.colorCustomizations": {
"activityBar.background": "#1accff",
"activityBar.activeBorder": "#df00ad",
"activityBar.foreground": "#15202b",
"activityBar.inactiveForeground": "#15202b99",
"activityBarBadge.background": "#df00ad",
"activityBarBadge.foreground": "#e7e7e7",
"titleBar.activeBackground": "#00b3e6",
"titleBar.inactiveBackground": "#00b3e699",
"titleBar.activeForeground": "#15202b",
"titleBar.inactiveForeground": "#15202b99",
"statusBar.background": "#00b3e6",
"statusBarItem.hoverBackground": "#008bb3",
"statusBar.foreground": "#15202b"
},
"peacock.color": "#00b3e6"
}
70 changes: 65 additions & 5 deletions src/adagrams.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,68 @@
const Adagrams = {
drawLetters() {
// Implement this method for wave 1
let allLetters = {

Choose a reason for hiding this comment

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

This should be a const.

Style note: put each letter on it's own line.

A: 9, N: 6, B: 2, O: 8, C: 2, P: 2, D: 4, Q: 1, E: 12, R: 6, F: 2, S: 4, G: 3, T: 6, H: 2, U: 4, I: 9, V: 2, J: 1, W: 2, K: 1, X: 1, L: 4, Y: 2, M: 2, Z: 1 };

let letterScores = {

Choose a reason for hiding this comment

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

This should be a const.

Style note: put each letter on it's own line.

allLetters and letterScores are best placed inside the module, but above all the functions.

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 = {
drawLetters() {
let letters = [];
for(let letter in allLetters) {
for(let i = 0; i < allLetters[letter]; i += 1) {
letters.push(letter);
}
}

const myHand = [];

for(let i = 0; i < 10; i += 1) {
const myShuffledLetters = Math.floor(Math.random(letters) * (letters.length));

Choose a reason for hiding this comment

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

Walk through what this line of code is doing. Math.random() shouldn't take an argument.

myShuffledLetters should have a more semantically correct name.

There is a small bug where this could would allow you to pick 10 Z's (for instance), even though there aren't 10 Z's. What chance is necessary?

myHand.push(letters[myShuffledLetters]);
}
return myHand;
},
};

// Do not remove this line or your tests will break!
usesAvailableLetters(input, lettersInHand) {
const wordInput = input.toUpperCase().split("");
if (wordInput.length > lettersInHand.length) return false
const howManyTimes = {}
for(let i = 0; i < lettersInHand.length; i += 1) {
let char = lettersInHand[i];
if (howManyTimes[char]) {
howManyTimes[char] += 1; //if it exists, increment
} else {
howManyTimes[char] = 1;
}
}

for(let i = 0; i < wordInput.length; i += 1) {
let char = wordInput[i];
if (howManyTimes[char]) {
if (howManyTimes[char] > 0) {
howManyTimes[char] -= 1;
} else {
return false;
}
} else if (!howManyTimes[wordInput[i]]) {
return false;
}
}
return true;
},

scoreWord(word) {
let thisTotal = 0;
const newWord = word.toUpperCase().split("");
newWord.forEach((letter) => {
thisTotal += letterScores[letter];
});
if (word.length >= 7) {
return thisTotal + 8;
} else {

Choose a reason for hiding this comment

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

This else block isn't necessary.

return thisTotal;
}
}
}

// Do not remove this line or your tests will break
export default Adagrams;
1 change: 0 additions & 1 deletion test/adagrams.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ describe('Adagrams', () => {
describe('drawLetters', () => {
it('draws ten letters from the letter pool', () => {
const drawn = Adagrams.drawLetters();

expect(drawn).toHaveLength(10);
});

Expand Down