+ utils sort: sortBy

This commit is contained in:
tmshv committed 2016-03-03 01:29:46 +03:00
1 parent b21144e87d
commit ac0e7e089d
1 file changed
+11
+11
View File
@@ -12,4 +12,15 @@ export function sortByWeight(list, fn) {
.map(i => [fn(i), i])
.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;
}
}