You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
10 lines
429 B
10 lines
429 B
import ascending from "./ascending.js";
|
|
import group, {rollup} from "./group.js";
|
|
import sort from "./sort.js";
|
|
|
|
export default function groupSort(values, reduce, key) {
|
|
return (reduce.length !== 2
|
|
? sort(rollup(values, reduce, key), (([ak, av], [bk, bv]) => ascending(av, bv) || ascending(ak, bk)))
|
|
: sort(group(values, key), (([ak, av], [bk, bv]) => reduce(av, bv) || ascending(ak, bk))))
|
|
.map(([key]) => key);
|
|
}
|
|
|