Skip to content

Pr-1#1

Open
CheezItMan wants to merge 1 commit intomasterfrom
pr-1
Open

Pr-1#1
CheezItMan wants to merge 1 commit intomasterfrom
pr-1

Conversation

@CheezItMan
Copy link
Copy Markdown

This method will calculate the average of an array of grades.

@CheezItMan CheezItMan changed the title calculate average method Pr-1 Aug 13, 2019
Comment thread calculate_average.js
const calculateAverage = function calculateAverage(grades) {

let total = 0;
for (let i = 0; i < grades.length; i++) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What happens if grades is null? Does a statement need to be added for this edge case?

Comment thread calculate_average.js
total += grades[i];
}

let avg = total / grades.length;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What should be returned if there are no grades? I think you would get undefined here if grades is an empty array.

Comment thread calculate_average.js
@@ -0,0 +1,14 @@

const calculateAverage = function calculateAverage(grades) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider refactoring into an arrow function

Comment thread calculate_average.js
@@ -0,0 +1,14 @@

const calculateAverage = function calculateAverage(grades) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
if (grades == null || grades == undefined) {
return "No Grades Provided";
}

Comment thread calculate_average.js
@@ -0,0 +1,14 @@

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

remove the empty space

Comment thread calculate_average.js
const calculateAverage = function calculateAverage(grades) {

let total = 0;
for (let i = 0; i < grades.length; i++) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

forEach loop might be better for an array

Comment thread calculate_average.js
let avg = total / grades.length;

return avg;
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Semicolon can be removed here.

Comment thread calculate_average.js
const calculateAverage = function calculateAverage(grades) {

let total = 0;
for (let i = 0; i < grades.length; i++) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe consider using a for of loop:
for (grade of grades) {
}

Comment thread calculate_average.js
total += grades[i];
}

let avg = total / grades.length;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
let avg = total / grades.length;
const avg = total / grades.length;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants