Skip to content

Sphinx - Vlada Rapaport #44

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 8 commits into
base: main
Choose a base branch
from
Open

Sphinx - Vlada Rapaport #44

wants to merge 8 commits into from

Conversation

vladarap88
Copy link

No description provided.

Copy link

@yangashley yangashley left a comment

Choose a reason for hiding this comment

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

Nice job on js-adagrams!

@@ -1,15 +1,163 @@
export const drawLetters = () => {
// Implement this method for wave 1
const letterPool = {

Choose a reason for hiding this comment

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

While we use the const keyword to ensure the values cannot be reassigned, we should also use capital letters to convey to other devs the value is fixed.

Suggested change
const letterPool = {
const LETTER_POOL = {

}

const randomlyHand = [];
const lettersCountDict = {

Choose a reason for hiding this comment

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

Suggested change
const lettersCountDict = {
const LETTERS_COUNT = {

Recall that Javascript doesn't have dictionaries. It has objects.

Z: 0,
};

while (randomlyHand.length < 10) {

Choose a reason for hiding this comment

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

Prefer to reference the integer 10 with a variable. This makes your code more readable/self documenting because it clues other devs in to the meaning of 10.

Suggested change
while (randomlyHand.length < 10) {
const HAND_LENGTH = 10;
while (randomlyHand.length < HAND_LENGTH) {

};

while (randomlyHand.length < 10) {
const i = Math.floor(Math.random() * letters.length);

Choose a reason for hiding this comment

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

Prefer more descriptive name for this variable, maybe like randomIndex

Comment on lines +81 to +87
let wordLower = input.toLowerCase();

for (let letter of lettersInHand) {
lettersInHandCopy.push(letter.toLowerCase());
}

for (let letter of wordLower) {

Choose a reason for hiding this comment

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

2 notes:

  1. If your looping variable letter is not updated in the loop, then we should use const instead.

  2. To make your code more concise, call toLowerCase() when you need it:

Suggested change
let wordLower = input.toLowerCase();
for (let letter of lettersInHand) {
lettersInHandCopy.push(letter.toLowerCase());
}
for (let letter of wordLower) {
for (const letter of lettersInHand.toLowerCase()) {
lettersInHandCopy.push(letter);
}
for (const letter of input.toLowerCase()) {

if (!lettersInHandCopy.includes(letter)) {
return false;
} else {
lettersInHandCopy.splice(lettersInHandCopy.indexOf(letter), 1);

Choose a reason for hiding this comment

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

splice like python's remove has linear time complexity with respect to the length of the list. This won't be a problem for the size of data we're working with, but consider using a strategy of virtually "dividing" the list into a used and unused side. Swapping a value to the used side would be constant time!

};

export const scoreWord = (word) => {
// Implement this method for wave 3
const scoreDict = {

Choose a reason for hiding this comment

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

Suggested change
const scoreDict = {
const SCORE_DICT = {

Comment on lines +126 to +128
const bonusLengthMin = 7;
const bonusLengthMax = 10;
const bonusPoints = 8;

Choose a reason for hiding this comment

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

Use all caps for naming thees constant variables

};

export const highestScoreFrom = (words) => {
// Implement this method for wave 4
const tieBreakingLength = 10;

Choose a reason for hiding this comment

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

Suggested change
const tieBreakingLength = 10;
const TIE_BREAKING_LENGTH = 10;

let maxWord = words[0];
let maxScore = scoreWord(maxWord);

for (let i = 1; i < words.length; i++) {

Choose a reason for hiding this comment

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

Prefer for/of loop instead because we don't need i to access the letter we want to score.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants