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

Done all tasks#17

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

Open
vltkachenko-ua wants to merge8 commits intoHowProgrammingWorks:master
base:master
Choose a base branch
Loading
fromvltkachenko-ua:master

Conversation

@vltkachenko-ua
Copy link

No description provided.

// to calculate sumofall given arguments
// For example sum(1, 2, 3) shouldreturn6
letsum=0;
for(constiofargs)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 isi 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)return0;
letsum=0;
leti=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(leti=0;i<matrix.length;i++){
for(letj=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.

Expressionmatrix[i][j] repeated twice, and we have additionalmatrix[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
letmax=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.

// }
constages={};
for(constelementinpersons){
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'];
constperson=persons[element];
ages[element]=person.died-persons.born;

// gandhi: 79,
// hirohito: 88,
// }
constages={};
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

@tshemsedinovtshemsedinov left a comment

Choose a reason for hiding this comment

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

👍

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

Reviewers

@tshemsedinovtshemsedinovtshemsedinov approved these changes

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

@vltkachenko-ua@tshemsedinov

[8]ページ先頭

©2009-2025 Movatter.jp