-
Notifications
You must be signed in to change notification settings - Fork 65
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
Renato-JS-Nerdery-Challenge #64
base: master
Are you sure you want to change the base?
Conversation
JS-Algorithms/challenges.js
Outdated
const fact = (n) => { | ||
let result = 1; | ||
for (let i = n; i > 1; i--) { | ||
result = result * i; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better → result *= i;
JS-Algorithms/challenges.js
Outdated
// YOUR CODE HERE... | ||
if (!(n > 1)) return; | ||
|
||
const fact = (n) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better naming for variables and functions:
- The
fact
can becalculateFactorial
- You already had a variable named
n
it can becalculatedNumber
- You had a single parameter in your arrow function, so do that
const fact = n => {}
Remember that it's better to be very explicit with the names.
@@ -95,7 +113,24 @@ Since 10! === 3628800 and you sum 3 + 6 + 2 + 8 + 8 + 0 + 0 | |||
***** */ | |||
|
|||
const digitSum = (n) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a comment, you could avoid the function in this exercise.
const digitSum = (n) => {
if (!(n > 1)) return;
let result = 1;
let total = 0;
for (let i = n; i > 1; i--) {
result *= i;
}
const digits = String(BigInt(result));
for (const digit of digits) {
total += Number(digit);
}
return total;
};
JS-Algorithms/challenges.js
Outdated
for (let i = 1; i <= number; i++) { | ||
result += i ** i; | ||
} | ||
result = BigInt(result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do it in a single line: result = BigInt(result).toString();
@@ -118,7 +153,11 @@ Because the 12th index in the Fibonacci sequence is 144, and 144 has three digit | |||
***** */ | |||
|
|||
const fibIndex = (n) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work here!
I leave you some comments, in general you did a good work! Congrats! |
I improved the code based on recommendations, thanks for your feedback! |
This is my submit for the assignment