-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
Done all tasks #17
base: master
Are you sure you want to change the base?
Done all tasks #17
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; |
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
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
} | ||
while (i < args.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.
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; |
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.
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]; |
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.
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; |
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 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']; |
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.
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 = {}; |
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.
Use different variable name
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.
👍
No description provided.