Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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

Closed
skanndar wants to merge1 commit intoironhack-labs:masterfromskanndar:master

Conversation

skanndar
Copy link

No description provided.

return null;
}
var longest = arr[0];
for (var i = 0; i < arr.length; i++) {
Copy link
Contributor

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?
Copy link
Contributor

@tawebbcntawebbcnApr 1, 2020
edited
Loading

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) {
Copy link
Contributor

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) {
Copy link
Contributor

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 == "") {
Copy link
Contributor

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.

@tawebbcn
Copy link
Contributor

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.

@skanndar
Copy link
Author

skanndar commentedApr 1, 2020 via email

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> .

@skanndar
Copy link
Author

skanndar commentedApr 1, 2020 via email

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> .

@tawebbcn
Copy link
Contributor

  • For the avg function Jasmine check you could use the following methods to transform the number to the required one.

return parseFloat(avg.toFixed(2));

  • For the validation check on averageNumber function, instead of (arr == "") just write this in the validation of the if statement:

(arr.length === 0)

Try to write instead of copy/pasting in case your are having issues with format.
Both worked correctly on our side, let us know if it didn't for you.

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

@tawebbcntawebbcntawebbcn left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@skanndar@tawebbcn

[8]ページ先頭

©2009-2025 Movatter.jp