Category
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)
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
Arrange 2 objects in a tuple by their length. Useful for situations where you are iterating
a
orb
depending on which is larger.Time complexity: O(1)
Space complexity: O(1)