image-js
Version:
Image processing and manipulation in JavaScript
33 lines • 1.13 kB
JavaScript
/**
* Sort array of matches by source index and then destination index.
* @param matches - Array of matches to sort.
* @returns Sorted copy of the array of matches.
*/
export function sortBySourceDest(matches) {
const sorted = matches.slice();
sorted.sort((match1, match2) => {
if (match1.sourceIndex < match2.sourceIndex)
return -1;
if (match1.sourceIndex > match2.sourceIndex)
return 1;
return match1.destinationIndex - match2.destinationIndex;
});
return sorted;
}
/**
* Sort array of matches by destination index and then source index.
* @param matches - Array of matches to sort.
* @returns Sorted copy of the array of matches.
*/
export function sortByDestSource(matches) {
const sorted = matches.slice();
sorted.sort((match1, match2) => {
if (match1.destinationIndex < match2.destinationIndex)
return -1;
if (match1.destinationIndex > match2.destinationIndex)
return 1;
return match1.sourceIndex - match2.sourceIndex;
});
return sorted;
}
//# sourceMappingURL=sortBySourceDest.js.map