Skip to content

warm up done #236

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 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions nodejs/week1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Node.js
node_modules/
npm-debug.log
39 changes: 39 additions & 0 deletions nodejs/week1/avg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
console.log("Hi I'm avg.js");

const args = process.argv.slice(2);


function checkIfNumber(arg) {
return !isNaN(parseFloat(arg)) && isFinite(arg);
};
Comment on lines +6 to +8
Copy link

Choose a reason for hiding this comment

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

Very nice function! 🔥


function getAVG(args) {
const sum = args.reduce((acc, arg) => acc + parseFloat(arg), 0);
return sum / args.length;
}
Comment on lines +10 to +13
Copy link

Choose a reason for hiding this comment

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

Nice! The casing of the name of the function is a bit odd though, it should be either getAvg or getAverage in my opinion.


function main(args) {


if (args.length === 0) {
console.log("No arguments provided, please provide at least one number");
return;
}

if (!args.every(checkIfNumber)) {
console.log("Please provide only numbers");
return;
}

const average = getAVG(args);
console.log(`The average of ${args.join(", ")} is ${average}`);
return average;
}





console.log(main(args));
Copy link

Choose a reason for hiding this comment

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

What is the motivation for this console.log? You already do all the printing in the main() function itself, this line of code will either output an unncesessary undefined or a duplicate value for average, which was already printed. You can remove this.



Loading