Skip to content

I typescrpted it... #12

@jonathan-meyer

Description

@jonathan-meyer
const combo = <T>(a: T[], min?: number, max?: number): T[][] => {
  min = min || 1;
  max = Math.min(max || a.length, a.length);

  const fn = (n: number, src: T[], got: T[], all: T[][]) => {
    if (n == 0) {
      if (got.length > 0) {
        all[all.length] = got;
      }

      return;
    }

    for (let j = 0; j < src.length; j++) {
      fn(n - 1, src.slice(j + 1), got.concat([src[j]]), all);
    }

    return;
  };

  const all = [];

  for (let i = min; i <= max; i++) {
    fn(i, a, [], all);
  }

  return all;
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions