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

Too much temporary data and inefficient operations #14

Open
lzralbu opened this issue Jan 11, 2021 · 1 comment
Open

Too much temporary data and inefficient operations #14

lzralbu opened this issue Jan 11, 2021 · 1 comment
Labels
optimization Improving speed or space efficiency
Milestone

Comments

@lzralbu
Copy link

lzralbu commented Jan 11, 2021

Consider using the standard .values instead of the custom .toArray. Besides, I'd also suggest to use Set's methods as much as possible since it is implemented as a hashset, which is very efficient, instead of relying on Array's methods which usually take at least linear time.

For example, .intersection could be implemented along the following lines

intersection(s1, s2) {
  s3 = new Set();
  s1.forEach(value => {
    if (s2.has(value)) {
      s3.add(value);
    }
  });
  return s3;
}
@jpbulman
Copy link
Owner

@lzralbu That's a good idea! It's not entirely space efficient either. If you'd like to take this up and make a pr, feel free!

@jpbulman jpbulman added this to the 0.0.3 milestone Jan 11, 2021
@jpbulman jpbulman added the optimization Improving speed or space efficiency label Jan 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimization Improving speed or space efficiency
Projects
None yet
Development

No branches or pull requests

2 participants