(collection, comparator, mapper)
| 817 | } |
| 818 | |
| 819 | export 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 | |
| 848 | export function maxFactory(collection, comparator, mapper) { |
| 849 | if (!comparator) { |
no test coverage detected