MCPcopy
hub / github.com/immutable-js/immutable-js / sortFactory

Function sortFactory

src/Operations.js:819–846  ·  view source on GitHub ↗
(collection, comparator, mapper)

Source from the content-addressed store, hash-verified

817}
818
819export function sortFactory(collection, comparator, mapper) {
820 if (!comparator) {
821 comparator = defaultComparator;
822 }
823 const isKeyedCollection = isKeyed(collection);
824 let index = 0;
825 const entries = collection
826 .toSeq()
827 .map((v, k) => [k, v, index++, mapper ? mapper(v, k, collection) : v])
828 .valueSeq()
829 .toArray();
830 entries
831 .sort((a, b) => comparator(a[3], b[3]) || a[2] - b[2])
832 .forEach(
833 isKeyedCollection
834 ? (v, i) => {
835 entries[i].length = 2;
836 }
837 : (v, i) => {
838 entries[i] = v[1];
839 }
840 );
841 return isKeyedCollection
842 ? KeyedSeq(entries)
843 : isIndexed(collection)
844 ? IndexedSeq(entries)
845 : SetSeq(entries);
846}
847
848export function maxFactory(collection, comparator, mapper) {
849 if (!comparator) {

Callers 6

sortMethod · 0.90
sortByMethod · 0.90
sortMethod · 0.90
sortByMethod · 0.90
sortFunction · 0.90
sortByFunction · 0.90

Calls 11

isKeyedFunction · 0.90
KeyedSeqClass · 0.90
isIndexedFunction · 0.90
IndexedSeqClass · 0.90
SetSeqClass · 0.90
forEachMethod · 0.80
toArrayMethod · 0.65
valueSeqMethod · 0.65
mapMethod · 0.65
toSeqMethod · 0.65
sortMethod · 0.65

Tested by

no test coverage detected