Skip to content

Conversation

dianprsty
Copy link
Contributor

Hello, I have finished challenge 2 to recreate challenge 1 using nodejs
This is what I already do :

Thanks,
Dian P.

Copy link
Contributor

@ianriizky ianriizky left a comment

Choose a reason for hiding this comment

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

Cause we will learn file management later on in the express.js basic course, I suggest that you locate the code as per the guidance below:

  1. /src for all of the JavaScript core code, such as factorial-functional, factorial-oop, fizzbuzz-functional, fizzbuzz-oop, etc. Also, put any utils, shared, or helpers code in this folder.
  2. /bin for all the JavaScript code related to the terminal execution process.
  3. /pages for all the HTML page that has been created in Chapter 1, including some of the JavaScript code needed to run the HTML input like JavaScript DOM etc.

Thank you for the pull request.


for (let argument of cliArguments) {
if (!validateArgument(argument)) {
throw new Error(`invalid argument ${argument}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

You could make a better exception throwing by setting a specific Error instance rather than just a basic Error. See details here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects#error_objects.

@@ -0,0 +1,3 @@
export const destructureArgument = argument => argument.split("=");
Copy link
Contributor

Choose a reason for hiding this comment

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

Move this file into /src folder. I'll explain it later at the end of this review.

Comment on lines 1 to 5
import { countFactorial } from "../../pages/functional/js/factorial.js";

import { Factorial } from "../../pages/oop/js/Factorial.js";

import { handleArgument } from "./handleArgument.js";
Copy link
Contributor

Choose a reason for hiding this comment

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

No need extra line break for each part of the import code here.

let result = 0;

if (!["oop", "functional"].includes(type)) {
throw new Error(`invalid type ${type}. must be "oop" or "functional"`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on lines 11 to 21
if (!["oop", "functional"].includes(type)) {
throw new Error(`invalid type ${type}. must be "oop" or "functional"`);
}

if (!["loop", "recursive"].includes(method)) {
throw new Error(`invalid method ${method}. must be "loop" or "recursive"`);
}

if (typeof parseInt(n) != "number") {
throw new Error(`invalid number ${n}. n should be a number"`);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Put this validation code in the handleArgument file so this file will be focused on running the action/logic part.

Comment on lines 28 to 29
const factorial = new Factorial(n);
result = factorial.count(method);
Copy link
Contributor

Choose a reason for hiding this comment

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

Simplify this by just trimming the code into one line.

}
}

export {
Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -0,0 +1,17 @@
import { countFactorial } from "../js/factorial.js";

document.getElementById("form").addEventListener("submit", function (event) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Turn back this file into functional folder. I'll explain it later at the end of this review.

@dianprsty dianprsty closed this Nov 3, 2023
@dianprsty dianprsty reopened this Nov 3, 2023
@dianprsty
Copy link
Contributor Author

Hello @ianriizky ,

I have already refactor 2nd challenge's code.
I move both oop and functional code to /src and includes all supporting code in /utils

this is the commit : refactor : move js to src and utility to utils

Thanks,
Dian

@dianprsty dianprsty closed this Nov 3, 2023
@dianprsty dianprsty reopened this Nov 3, 2023
@dianprsty
Copy link
Contributor Author

I found mistakes in previous commit, it is in input validation and I have fix it in here :
fix : fix wrong validation

Copy link
Contributor

@ianriizky ianriizky left a comment

Choose a reason for hiding this comment

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

Please check the review above, thank you.

Comment on lines +4 to +5
let parsedInput = parseNumber(input);
if (typeof parsedInput != "number") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add line break between this code.

@@ -0,0 +1,19 @@
export const validateFactorialMethod = method => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think these function along with the validateApproach.js can be unified into one function. Then the required list of method (loop, recursive, functional, oop, etc.) can be passed as a paremeter of the function.

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