[www] sort eslinted
This commit is contained in:
1 parent
acaec420c7
commit
44e5f832b6
1 file changed
+17
-17
+17
-17
@@ -1,26 +1,26 @@
|
|||||||
export function sortByPattern(list, pattern, map) {
|
export function sortByPattern(list, pattern, map) {
|
||||||
let weight = i => {
|
let weight = i => {
|
||||||
const index = pattern.indexOf(map(i));
|
const index = pattern.indexOf(map(i))
|
||||||
return index > -1 ? pattern.length - index : 0;
|
return index > -1 ? pattern.length - index : 0
|
||||||
};
|
}
|
||||||
|
|
||||||
return sortByWeight(list, weight)
|
return sortByWeight(list, weight)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sortByWeight(list, fn) {
|
export function sortByWeight(list, fn) {
|
||||||
return list
|
return list
|
||||||
.map(i => [fn(i), i])
|
.map(i => [fn(i), i])
|
||||||
.sort((a, b) => b[0] - a[0])
|
.sort((a, b) => b[0] - a[0])
|
||||||
.map(i => i[1]);
|
.map(i => i[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sortBy(fn) {
|
export function sortBy(fn) {
|
||||||
return (i1, i2) => {
|
return (i1, i2) => {
|
||||||
let t1 = fn(i1);
|
let t1 = fn(i1)
|
||||||
let t2 = fn(i2);
|
let t2 = fn(i2)
|
||||||
|
|
||||||
if (t1 < t2) return 1;
|
if (t1 < t2) return 1
|
||||||
if (t1 > t2) return -1;
|
if (t1 > t2) return -1
|
||||||
return 0;
|
return 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user