Skip to content

Done all tasks - #17

Open
vltkachenko-ua wants to merge 8 commits into
HowProgrammingWorks:masterfrom
vltkachenko-ua:master
Open

Done all tasks#17
vltkachenko-ua wants to merge 8 commits into
HowProgrammingWorks:masterfrom
vltkachenko-ua:master

Conversation

@vltkachenko-ua

Copy link
Copy Markdown

No description provided.

Comment thread 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;

Copy link
Copy Markdown
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 thread Exercises/4-do-while.js Outdated
Comment on lines +10 to +11
}
while (i < args.length);

Copy link
Copy Markdown
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);

Comment thread 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;

Copy link
Copy Markdown
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 👍

Comment thread 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];

Copy link
Copy Markdown
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.

Comment thread 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;

Copy link
Copy Markdown
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.

Comment thread Exercises/7-ages.js Outdated
// }
const ages = {};
for (const element in persons) {
ages[element] = persons[element]['died'] - persons[element]['born'];

Copy link
Copy Markdown
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;
Comment thread Exercises/7-ages.js Outdated
// gandhi: 79,
// hirohito: 88,
// }
const ages = {};

Copy link
Copy Markdown
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

@tshemsedinov tshemsedinov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

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

Labels

None yet

2 participants