+ utils sort: sortBy
This commit is contained in:
1 parent
b21144e87d
commit
ac0e7e089d
1 file changed
+11
@@ -13,3 +13,14 @@ export function sortByWeight(list, fn) {
|
||||
.sort((a, b) => b[0] - a[0])
|
||||
.map(i => i[1]);
|
||||
}
|
||||
|
||||
export function sortBy(fn) {
|
||||
return (i1, i2) => {
|
||||
let t1 = fn(i1);
|
||||
let t2 = fn(i2);
|
||||
|
||||
if (t1 < t2) return 1;
|
||||
if (t1 > t2) return -1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user