- Notifications
You must be signed in to change notification settings - Fork6.7k
[BCN-FT-ALEX A.] - done#1628
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
return null; | ||
} | ||
var longest = arr[0]; | ||
for (var i = 0; i < arr.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.
The conditional inside the for loop works good but you could refactor it a little bit better.
if (arr[i].length > longest.length) {
longest = arr[i];
}
Removes the continue and else part to make it shorter and more concise.
} else if (arr2[i] === true) { | ||
total++; | ||
} else { | ||
//HOw to throw an error? |
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.
throw new Error("Unsupported data type sir or ma'am") and it will check correct :)
total += arr2[i].length; | ||
} else if (typeof arr2[i] === "number") { | ||
total += arr2[i]; | ||
} else if (arr2[i] === true) { |
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 can add this condition with an || operator to the second condition to reduce code. The numeric value of the boolean true is always 1 so it will match the same statement.
return total; | ||
} | ||
// function sum(arr2) { |
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.
remember to remove unused code snippets (even the commented ones like this) when doing pull request to make your code cleaner.
// Iteration #4: Calculate the average | ||
// Level 1: Array of numbers | ||
const numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9]; | ||
function averageNumbers(arr) { | ||
if (arr == "") { |
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.
Although this works, for best practices we would recommend to use something like ( arr.length === 0 ) to check if an array is empty. Using double equal "==" means you are using coercion and converting data types from an array to a string and it might be a little bit confusing to read and create issues in the long run.
Excellent work! only a couple of bonuses left. Very good use of double for loop, counters and methods. We will send you the solution for you to check the two bonuses you were having difficulties. |
Hey,thank you for the feedback.On line160 I make a comment://When trying in repl.it it gives the expected result '5.7', however,jasmin doesnt take it, Expected 5.111111111111111 to be 5.11.I couldn't figure out why. Any idea?El mié., 1 abr. 2020 a las 19:02, tawebbcn (<notifications@github.com>)escribió: … Excellent work! only a couple of bonuses left. Very good use of double for loop, counters and methods. We will send you the solution for you to check the two bonuses you were having difficulties. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <#1628 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ADZJ5M42IISY4OW57EVOKCTRKNXRDANCNFSM4LYD754A> . |
when fixing this:+function averageNumbers(arr) {+ if (arr == "") {Although this works, for best practices we would recommend to use somethinglike ( arr.length === 0 ) to check if an array is empty. Using double equal"==" means you are using coercion and converting data types from an arrayto a string and it might be a little bit confusing to read and createissues in the long run.Jasmin goes from green to red. I don't understand why.El mié., 1 abr. 2020 a las 18:09, tawebbcn (<notifications@github.com>)escribió: … ***@***.**** commented on this pull request. ------------------------------ In src/functions-and-arrays.js <#1628 (comment)> : > // Iteration#4: Calculate the average // Level 1: Array of numbers const numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9]; +function averageNumbers(arr) { + if (arr == "") { Although this works, for best practices we would recommend to use something like ( arr.length === 0 ) to check if an array is empty. Using double equal "==" means you are using coercion and converting data types from an array to a string and it might be a little bit confusing to read and create issues in the long run. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <#1628 (review)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ADZJ5M2DVBGUHOOAEVUNCWTRKNRK5ANCNFSM4LYD754A> . |
return parseFloat(avg.toFixed(2));
(arr.length === 0) Try to write instead of copy/pasting in case your are having issues with format. |
No description provided.