Skip to content

Pullrequest#1

Open
kaydentsoftwire wants to merge 24 commits intomainfrom
pullrequest
Open

Pullrequest#1
kaydentsoftwire wants to merge 24 commits intomainfrom
pullrequest

Conversation

@kaydentsoftwire
Copy link
Copy Markdown
Owner

No description provided.

Copy link
Copy Markdown

@AmeliaIsCoding AmeliaIsCoding left a comment

Choose a reason for hiding this comment

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

Looks great! A few comments on things to change :)

Comment thread index.ts
const upperValue: string | null = prompt("What value would you like FizzBuzz to go up to? ");
console.log(`We go up to ${upperValue}`);

function divisibleBy(num: number, divisor: number): boolean { return num % divisor == 0 };
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Move this function declaration to a different file and export it to be used in this file. You could call the new file helpers.ts or something like that and you should probably put it in a folder called src

The function makes sense on its own so it belongs in its own file :)

Comment thread index.ts
const upperValue: string | null = prompt("What value would you like FizzBuzz to go up to? ");
console.log(`We go up to ${upperValue}`);

function divisibleBy(num: number, divisor: number): boolean { return num % divisor == 0 };
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I know num and divisor are both of the same type but people tend to use triple equals instead of double equals anyway so I would change the double equals to a triple equals

Comment thread index.ts

function divisibleBy(num: number, divisor: number): boolean { return num % divisor == 0 };

const key: {[index: number]: Function } = {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

what does key mean? can we name this something more informative maybe?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Also can we be more specific with the type of function? it appears to always be (answer: string[]) => string[]

Comment thread index.ts
answer.push('Bang');
return answer;
} else {
return ['Bang'];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why don't we want to push "Bang" in this else clause?

Comment thread index.ts
return ['Bang'];
}
},
11: (answer: string[]) => answer = ['Bong'],
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

could we change this to 11: (answer: string[]) => ['Bong'] ?

Comment thread index.ts

}

const fizzBuzz = (upperValue: string | null) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

should we explicitly treat the case where upperValue is null? how about console logging an error message and returning from the function?

Comment thread index.ts
}

const fizzBuzz = (upperValue: string | null) => {
for (let n = 0; n <= Number(upperValue); n++) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

if we explicitly treat the case where upperValue is null, we don't need to convert upperValue to a number here

Comment thread index.ts
let answer: string[] = [];

for (const num of Object.keys(key)) {
if (divisibleBy(n, Number(num))) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

is this type conversion needed? what type does typescript think num is?

Comment thread index.ts
}
}

if (answer.length == 0) { answer.push(String(n))}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

instead of using String(n) we could use n.toString(), I think this is more conventional

Comment thread test.ts
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe you meant to delete this file before making the pull request! :)

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