+12
@@ -0,0 +1,12 @@
|
||||
import none from "./none.js";
|
||||
|
||||
export default function(series) {
|
||||
var peaks = series.map(peak);
|
||||
return none(series).sort(function(a, b) { return peaks[a] - peaks[b]; });
|
||||
}
|
||||
|
||||
function peak(series) {
|
||||
var i = -1, j = 0, n = series.length, vi, vj = -Infinity;
|
||||
while (++i < n) if ((vi = +series[i][1]) > vj) vj = vi, j = i;
|
||||
return j;
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import none from "./none.js";
|
||||
|
||||
export default function(series) {
|
||||
var sums = series.map(sum);
|
||||
return none(series).sort(function(a, b) { return sums[a] - sums[b]; });
|
||||
}
|
||||
|
||||
export function sum(series) {
|
||||
var s = 0, i = -1, n = series.length, v;
|
||||
while (++i < n) if (v = +series[i][1]) s += v;
|
||||
return s;
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import ascending from "./ascending.js";
|
||||
|
||||
export default function(series) {
|
||||
return ascending(series).reverse();
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
import appearance from "./appearance.js";
|
||||
import {sum} from "./ascending.js";
|
||||
|
||||
export default function(series) {
|
||||
var n = series.length,
|
||||
i,
|
||||
j,
|
||||
sums = series.map(sum),
|
||||
order = appearance(series),
|
||||
top = 0,
|
||||
bottom = 0,
|
||||
tops = [],
|
||||
bottoms = [];
|
||||
|
||||
for (i = 0; i < n; ++i) {
|
||||
j = order[i];
|
||||
if (top < bottom) {
|
||||
top += sums[j];
|
||||
tops.push(j);
|
||||
} else {
|
||||
bottom += sums[j];
|
||||
bottoms.push(j);
|
||||
}
|
||||
}
|
||||
|
||||
return bottoms.reverse().concat(tops);
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
export default function(series) {
|
||||
var n = series.length, o = new Array(n);
|
||||
while (--n >= 0) o[n] = n;
|
||||
return o;
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import none from "./none.js";
|
||||
|
||||
export default function(series) {
|
||||
return none(series).reverse();
|
||||
}
|
||||
Reference in New Issue
Block a user