Skip to content

Done all tasks #17

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

vltkachenko-ua
Copy link

No description provided.

// 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;
Copy link
Member

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

Comment on lines 10 to 11
}
while (i < args.length);
Copy link
Member

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);

// For example sum(1, 2, 3) should return 6
if (args.length < 1) return 0;
let sum = 0;
let i = 0;
Copy link
Member

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 👍

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];
Copy link
Member

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.

// 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;
Copy link
Member

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.

// }
const ages = {};
for (const element in persons) {
ages[element] = persons[element]['died'] - persons[element]['born'];
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
ages[element] = persons[element]['died'] - persons[element]['born'];
const person = persons[element];
ages[element] = person.died - persons.born;

// gandhi: 79,
// hirohito: 88,
// }
const ages = {};
Copy link
Member

Choose a reason for hiding this comment

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

Use different variable name

Copy link
Member

@tshemsedinov tshemsedinov left a comment

Choose a reason for hiding this comment

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

👍

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants