Skip to content

Too much temporary data and inefficient operations #14

@lzralbu

Description

@lzralbu

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    optimizationImproving speed or space efficiency

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions