-
Notifications
You must be signed in to change notification settings - Fork 2
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 #1
base: master
Are you sure you want to change the base?
PR-1 #1
Conversation
@@ -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.
Here's a one-off single comment!
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.
LGTM
|
||
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.
I like what you've done here.
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.
ok
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.
you could put grades.length into a variable to avoid recalculating it every loop
total += grades[i]; | ||
} | ||
|
||
let avg = total / grades.length; |
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.
does avg end up as an integer or a float? If all the grades are whole numbers, it might be an integer, but you probably want to force it to do float math
total += grades[i]; | ||
} | ||
|
||
let avg = total / grades.length; |
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.
avg could also be const
instead of a let
|
||
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.
instead of storing the average as a variable, you could return the calculation return value directly
return avg; | |
return total / grades.length; |
total += grades[i]; | ||
} | ||
|
||
let avg = total / grades.length; |
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.
let avg = total / grades.length; | |
let avg = total / parseFloat(grades.length); |
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.
Approved
|
||
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 delete line 9 and just do:
return avg; | |
return total / grades.length; |
total += grades[i]; | ||
} | ||
|
||
let avg = total / grades.length; |
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 renaming avg to avgGrades to be clearer.
return avg; | ||
}; | ||
|
||
export default calculateAverage; |
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.
lgtm
return avg; | ||
}; | ||
|
||
export default calculateAverage; |
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.
Might want to add a newline here
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.
This is really clean and readable. well sone
This method will calculate the average of an array of grades.