Function largeToSmall

  • Category

    Arrange 2 objects in a tuple by their length. Useful for situations where you are iterating a or b depending on which is larger.

    Time complexity: O(1)

    Space complexity: O(1)

    Type Parameters

    Parameters

    • a: A

      First object

    • b: B

      Second object

    Returns _ArrangedLargestToSmallest<A, B>

    const a = [1, 2];
    const b = [1, 2, 3];

    const [largest, smallest] = largeToSmall(a, b);

    console.log(largest); // [1, 2, 3]
    console.log(smallest); // [1, 2]

    If a does not have a length or size property

    Array

  • Category

    Arrange 2 objects in a tuple by their size. Useful for situations where you are iterating a or b depending on which is larger.

    Time complexity: O(1)

    Space complexity: O(1)

    Type Parameters

    Parameters

    • a: A

      First object

    • b: B

      Second object

    Returns _ArrangedLargestToSmallest<A, B>

    const a = new Set([1, 2]);
    const b = new Set([1, 2, 3]);

    const [largest, smallest] = largeToSmall(a, b);

    console.log(largest); // Set(3) { 1, 2, 3 }
    console.log(smallest); // Set(2) { 1, 2 }

    If a does not have a length or size property

    Array