-
Notifications
You must be signed in to change notification settings - Fork 5
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
PR-1 calculate average method #1
base: master
Are you sure you want to change the base?
Conversation
const calculateAverage = function calculateAverage(grades) { | ||
|
||
let total = 0; | ||
for (let i = 0; i < grades.length; i++) { |
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.
Can we use a .forEach
here instead?
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.
Or a .reduce
for the whole code block?
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.
Looks great! 😄 Threw in some style comments and a question
const calculateAverage = function calculateAverage(grades) { | ||
|
||
let total = 0; | ||
for (let i = 0; i < grades.length; i++) { |
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.
Or a .reduce
for the whole code block?
|
||
let avg = total / grades.length; | ||
|
||
return avg; |
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.
Can we combine lines 11 and line 9, ie return total/grades.length;
?
@@ -0,0 +1,14 @@ | |||
|
|||
const calculateAverage = function calculateAverage(grades) { |
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.
Can you tell me more why this function is assigned to a constant of the same name?
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.
Lines 5-7 to be revised.
Thanks
for (let i = 0; i < grades.length; i++) { | ||
total += grades[i]; | ||
} |
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.
Consider changing this loop to a forEach loop for better readibility.
@@ -0,0 +1,14 @@ | |||
|
|||
const calculateAverage = function calculateAverage(grades) { |
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.
Consider: arrow function syntax ➡️
No description provided.