Open
Conversation
Exercises/2-for-of.js
Outdated
| // to calculate sum of all given arguments | ||
| // For example sum(1, 2, 3) should return 6 | ||
| let sum = 0; | ||
| for (const i of args) sum += i; |
Member
There was a problem hiding this comment.
i is not a good naming for array element, it means index in array but here is i isn't an index
Exercises/4-do-while.js
Outdated
Comment on lines
10
to
11
| } | ||
| while (i < args.length); |
Member
There was a problem hiding this comment.
Better put it in a single line: } while (i < args.length);
Exercises/4-do-while.js
Outdated
| // For example sum(1, 2, 3) should return 6 | ||
| if (args.length < 1) return 0; | ||
| let sum = 0; | ||
| let i = 0; |
Member
There was a problem hiding this comment.
Having counter and not using pop/shift is much better for performance 👍
Exercises/6-matrix.js
Outdated
| for (let i = 0; i < matrix.length; i++) { | ||
| for (let j = 0; j < matrix[i].length; j++) { | ||
| //max = max < matrix[i][j] ? matrix[i][j] : max; | ||
| if (max < matrix[i][j]) max = matrix[i][j]; |
Member
There was a problem hiding this comment.
Expression matrix[i][j] repeated twice, and we have additional matrix[i] in line 6. See my solution to optimize code.
Exercises/6-matrix.js
Outdated
| // Use nested for loop to find max value in 2d matrix | ||
| // For example max([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) | ||
| // should return 9 | ||
| let max = 0; |
Member
There was a problem hiding this comment.
You can name variable as a function but it will be better to use different name.
Exercises/7-ages.js
Outdated
| // } | ||
| const ages = {}; | ||
| for (const element in persons) { | ||
| ages[element] = persons[element]['died'] - persons[element]['born']; |
Member
There was a problem hiding this comment.
Suggested change
| ages[element] = persons[element]['died'] - persons[element]['born']; | |
| const person = persons[element]; | |
| ages[element] = person.died - persons.born; |
Exercises/7-ages.js
Outdated
| // gandhi: 79, | ||
| // hirohito: 88, | ||
| // } | ||
| const ages = {}; |
Member
There was a problem hiding this comment.
Use different variable name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.