name of the properties to sort by, in order of priority
should sort be ascending? Pass boolean or object with boolean values for each property
Optional
defaultValues: Partial<Record<K[number], any>>values to use when properties are not defined in one of the objects
@example:
const videos = [
{ height: 480, bitrate: 300 },
{ height: 720, bitrate: 100 },
{ height: 720 },
{ height: 720, bitrate: 200 },
];
// Sort by height ascending, then by bitrate descending, and set default bitrate to 150
itemsMissing.sort(sortByMultiple(["height", "bitrate"], { height: true, bitrate: false }, { bitrate: 150 }));
// Result:
[
{ height: 480, bitrate: 300 },
{ height: 720, bitrate: 200 },
{ height: 720 }, // bitrate assumed to be 150
{ height: 720, bitrate: 100 },
]
Returns a function that can be used as a callback to
.sort()
method. Returned function will sort array by given properties.