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

warm up done #236

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

function getAVG(args) {
const sum = args.reduce((acc, arg) => acc + parseFloat(arg), 0);
return sum / args.length;
}

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


Loading