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

Renato-JS-Nerdery-Challenge #64

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Renato-JS-Nerdery-Challenge #64

wants to merge 8 commits into from

Conversation

rdev32
Copy link

@rdev32 rdev32 commented Apr 14, 2023

This is my submit for the assignment

@rdev32 rdev32 changed the title JS Fundamentals assignment Renato-JS-Nerdery-Challenge Apr 14, 2023
const fact = (n) => {
let result = 1;
for (let i = n; i > 1; i--) {
result = result * i;
Copy link

@caceres97 caceres97 Apr 22, 2023

Choose a reason for hiding this comment

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

Better → result *= i;

// YOUR CODE HERE...
if (!(n > 1)) return;

const fact = (n) => {
Copy link

@caceres97 caceres97 Apr 22, 2023

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 be calculateFactorial
  • You already had a variable named n it can be calculatedNumber
  • 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) => {
Copy link

@caceres97 caceres97 Apr 22, 2023

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;
};

for (let i = 1; i <= number; i++) {
result += i ** i;
}
result = BigInt(result);

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) => {

Choose a reason for hiding this comment

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

Good work here!

@caceres97
Copy link

I leave you some comments, in general you did a good work! Congrats!

@rdev32
Copy link
Author

rdev32 commented May 26, 2023

I improved the code based on recommendations, thanks for your feedback!

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