Skip to content
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

@AngularClass their solution is more elegant imo #1

Open
wants to merge 1 commit into
base: doctype_server_transfer
Choose a base branch
from
Open

@AngularClass their solution is more elegant imo #1

wants to merge 1 commit into from

Conversation

Owain94
Copy link

@Owain94 Owain94 commented Mar 27, 2017

No description provided.

Copy link

@leo6104 leo6104 left a comment

Choose a reason for hiding this comment

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

typescript Array some method can simplify the for loop

let headNode: any;

// tslint:disable-next-line:no-inferrable-types
for (let i: number = 0; i < document.childNodes.length; ++i) {
Copy link

@leo6104 leo6104 Mar 30, 2017

Choose a reason for hiding this comment

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

I think this code can be simplify with .some method
document.childNodes.some(child => isTag('html', child) && !!(rootNode = child));

}

// tslint:disable-next-line:no-inferrable-types
for (let i: number = 0; i < rootNode.childNodes.length; ++i) {
Copy link

@leo6104 leo6104 Mar 30, 2017

Choose a reason for hiding this comment

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

this for loop also can be
rootNode.childNodes.some(child => isTag('head', child) && !!(headNode = child));

Copy link

Choose a reason for hiding this comment

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

To sum up, 2 for loop code can be simplified to

  let rootNode: any = document; 
  let headNode: any;

  // tslint:disable-next-line:no-inferrable-types
  document.childNodes.some(child => isTag('html', child) && !!(rootNode = child));

  // tslint:disable-next-line:no-inferrable-types
  rootNode.childNodes.some(child => isTag('head', child) && !!(headNode = child));

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

Successfully merging this pull request may close these issues.

2 participants