Skip to content

7561 - Subtract #7680

Open
Open

Description

@LoTwT
type ConstructTuple<L extends number, R extends unknown[] = []> = R["length"] extends L ? R : ConstructTuple<L, [...R, unknown]>

// M => minuend, S => subtrahend
type Subtract<M extends number, S extends number> = ConstructTuple<M> extends [...subtrahend: ConstructTuple<S>, ...rest: infer Rest] ? Rest["length"] : never

Activity

  1. added
    answer
    en
    on Mar 22, 2022
  2. dimitropoulos commented on Jan 22, 2023

    @dimitropoulos
    Contributor

    WOW! What an elegant solution! I'll feature it on the video solutions!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    7561answeren

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions