-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: main
Are you sure you want to change the base?
warm up done #236
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Node.js | ||
node_modules/ | ||
npm-debug.log |
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; | ||
} | ||
Comment on lines
+10
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the motivation for this |
||
|
||
|
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.
Very nice function! 🔥