From 3dab80b8f53b2adb3ae36e79b25383f123101670 Mon Sep 17 00:00:00 2001 From: FEKETE Jean-Daniel Date: Thu, 31 Dec 2020 23:19:36 +0100 Subject: [PATCH] apply lebab -t arrow-return that cleaned up the code a lot --- src/barycenter_order.js | 8 ++------ src/count_crossings.js | 16 ++++------------ src/cuthill_mckee_order.js | 14 ++++---------- src/fiedler.js | 4 +--- src/graph.js | 19 ++++++------------- src/graph2distmat.js | 4 +--- src/hcluster.js | 4 +--- src/mat2graph.js | 4 +--- src/optimal_leaf_order.js | 4 +--- src/order.js | 8 ++------ src/pcp.js | 4 +--- src/sort_order.js | 8 ++------ test/count_crossings-test.js | 28 +++++++--------------------- test/env-assert.js | 4 +--- test/graph2mat-test.js | 8 ++------ test/order-test.js | 8 ++------ 16 files changed, 38 insertions(+), 107 deletions(-) diff --git a/src/barycenter_order.js b/src/barycenter_order.js index 5f92da6..e277e70 100644 --- a/src/barycenter_order.js +++ b/src/barycenter_order.js @@ -50,12 +50,8 @@ export function barycenter(graph, comp, max_iter) { let neighbors; let med; - layer1 = comp.filter((n) => { - return graph.outDegree(n) !== 0; - }); - layer2 = comp.filter((n) => { - return graph.inDegree(n) !== 0; - }); + layer1 = comp.filter(n => graph.outDegree(n) !== 0); + layer2 = comp.filter(n => graph.inDegree(n) !== 0); if (comp.length < 3) { return [layer1, layer2, count_crossings(graph, layer1, layer2)]; } diff --git a/src/count_crossings.js b/src/count_crossings.js index 8e239b8..d7cb3eb 100644 --- a/src/count_crossings.js +++ b/src/count_crossings.js @@ -21,12 +21,8 @@ export function count_crossings(graph, north, south) { const comp = permutation(graph.nodes().length); if (north === undefined) { - north = comp.filter((n) => { - return graph.outDegree(n) !== 0; - }); - south = comp.filter((n) => { - return graph.inDegree(n) !== 0; - }); + north = comp.filter(n => graph.outDegree(n) !== 0); + south = comp.filter(n => graph.inDegree(n) !== 0); } // Choose the smaller axis @@ -42,13 +38,9 @@ export function count_crossings(graph, north, south) { for (i = 0; i < north.length; i++) { if (invert) { - n = graph.inEdges(north[i]).map((e) => { - return south_inv[e.target.index]; - }); + n = graph.inEdges(north[i]).map(e => south_inv[e.target.index]); } else { - n = graph.outEdges(north[i]).map((e) => { - return south_inv[e.source.index]; - }); + n = graph.outEdges(north[i]).map(e => south_inv[e.source.index]); } n.sort(cmp_number); southsequence = southsequence.concat(n); diff --git a/src/cuthill_mckee_order.js b/src/cuthill_mckee_order.js index fd9a08e..b0309fb 100644 --- a/src/cuthill_mckee_order.js +++ b/src/cuthill_mckee_order.js @@ -32,16 +32,10 @@ export function cuthill_mckee(graph, comp) { perm.push(n); e = graph .edges(n) - .map((edge) => { - return graph.other(edge, n).index; - }) - .filter((n) => { - return !visited[n] && n in inv; - }) - .sort((a, b) => { - // ascending by degree - return graph.degree(a) - graph.degree(b); - }); + .map(edge => graph.other(edge, n).index) + .filter(n => !visited[n] && n in inv) + .sort((a, b) => // ascending by degree + graph.degree(a) - graph.degree(b)); e.forEach(queue.push, queue); } diff --git a/src/fiedler.js b/src/fiedler.js index 1f5e96a..aefb902 100644 --- a/src/fiedler.js +++ b/src/fiedler.js @@ -38,9 +38,7 @@ export function fiedler_vector(B, eps) { const n = B.length; const // Copy B - Bhat = B.map((row) => { - return row.slice(); - }); + Bhat = B.map(row => row.slice()); let i; let j; diff --git a/src/graph.js b/src/graph.js index 9705745..4396d06 100644 --- a/src/graph.js +++ b/src/graph.js @@ -15,11 +15,7 @@ export function graph(nodes, links, directed) { return graph; }; - graph.nodes_indices = () => { - return nodes.map((n) => { - return n.index; - }); - }; + graph.nodes_indices = () => nodes.map(n => n.index); graph.generate_nodes = (n) => { nodes = []; @@ -32,11 +28,10 @@ export function graph(nodes, links, directed) { links = x; return graph; }; - graph.links_indices = () => { - return links.map((l) => { - return { source: l.source.index, target: l.target.index }; - }); - }; + graph.links_indices = () => links.map(l => ({ + source: l.source.index, + target: l.target.index + })); graph.linkDistance = function (x) { if (!arguments.length) return linkDistance; linkDistance = typeof x === 'function' ? x : +x; @@ -226,9 +221,7 @@ export function graph(nodes, links, directed) { comps.push(ccomp); } } - comps.sort((a, b) => { - return b.length - a.length; - }); + comps.sort((a, b) => b.length - a.length); return comps; } diff --git a/src/graph2distmat.js b/src/graph2distmat.js index dda2804..db269b7 100644 --- a/src/graph2distmat.js +++ b/src/graph2distmat.js @@ -34,9 +34,7 @@ export function valuemats_reorder(valuemats, leaforder, comps) { let orders = valuemats.map(leaforder); if (comps) { - orders = orders.map((d, i) => { - return permute(comps[i], d); - }); + orders = orders.map((d, i) => permute(comps[i], d)); } return orders.reduce(flatten); } diff --git a/src/hcluster.js b/src/hcluster.js index 828e989..275ad16 100644 --- a/src/hcluster.js +++ b/src/hcluster.js @@ -151,9 +151,7 @@ export function hcluster() { hcluster.distanceMatrix = function (x) { if (!arguments.length) return distMatrix; - distMatrix = x.map((y) => { - return y.slice(0); - }); + distMatrix = x.map(y => y.slice(0)); return hcluster; }; diff --git a/src/mat2graph.js b/src/mat2graph.js index 19e23c1..1deb849 100644 --- a/src/mat2graph.js +++ b/src/mat2graph.js @@ -25,8 +25,6 @@ export function mat2graph(mat, directed) { } } return graph(nodes, links, directed) - .linkDistance((l, i) => { - return 1 + max_value - l.value; - }) + .linkDistance((l, i) => 1 + max_value - l.value) .init(); } diff --git a/src/optimal_leaf_order.js b/src/optimal_leaf_order.js index 75e70a0..cfcf1d8 100644 --- a/src/optimal_leaf_order.js +++ b/src/optimal_leaf_order.js @@ -140,9 +140,7 @@ export function optimal_leaf_order() { optimal_leaf_order.distance_matrix = function (x) { if (!arguments.length) return distanceMatrix; // copy - distanceMatrix = x.map((y) => { - return y.slice(0); - }); + distanceMatrix = x.map(y => y.slice(0)); return optimal_leaf_order; }; optimal_leaf_order.distanceMatrix = optimal_leaf_order.distance_matrix; // compatibility diff --git a/src/order.js b/src/order.js index 71ae942..630f03f 100644 --- a/src/order.js +++ b/src/order.js @@ -133,9 +133,7 @@ export function order() { } if (i0 !== 0) { perm = permutation(i0).concat( - perm.map((v) => { - return v + i0; - }) + perm.map(v => v + i0) ); } if (orig.length > j0) { @@ -332,9 +330,7 @@ export function order() { } function _perm_insert(perm, i, nv) { - perm = perm.map((v) => { - return v < nv ? v : v + 1; - }); + perm = perm.map(v => v < nv ? v : v + 1); perm.splice(i, 0, nv); return perm; } diff --git a/src/pcp.js b/src/pcp.js index 9397792..8c4adc5 100644 --- a/src/pcp.js +++ b/src/pcp.js @@ -42,9 +42,7 @@ export function dicts_to_array(dicts, keys) { } function abs_matrix(x) { - return x.map((y) => { - return y.map(Math.abs); - }); + return x.map(y => y.map(Math.abs)); } function pcp_flip_axes(perm, naxes, pcor) { diff --git a/src/sort_order.js b/src/sort_order.js index 63d7ce7..0e0b47b 100644 --- a/src/sort_order.js +++ b/src/sort_order.js @@ -1,15 +1,11 @@ import { permutation } from './permutation'; export function sort_order(v) { - return permutation(0, v.length).sort((a, b) => { - return v[a] - v[b]; - }); + return permutation(0, v.length).sort((a, b) => v[a] - v[b]); } export const sort_order_ascending = sort_order; export function sort_order_descending(v) { - return permutation(0, v.length).sort((a, b) => { - return v[b] - v[a]; - }); + return permutation(0, v.length).sort((a, b) => v[b] - v[a]); } diff --git a/test/count_crossings-test.js b/test/count_crossings-test.js index 690896a..c9e85d0 100644 --- a/test/count_crossings-test.js +++ b/test/count_crossings-test.js @@ -22,9 +22,7 @@ function naive_count_crossings(graph, north, south) { for (i = 0; i < north.length; i++) { v = north[i]; links = links.concat( - graph.outEdges(v).map((e) => { - return [inv_north[e.target.index], inv_south[e.source.index]]; - }) + graph.outEdges(v).map(e => [inv_north[e.target.index], inv_south[e.source.index]]) ); } for (i = 0; i < links.length; i++) { @@ -41,18 +39,10 @@ function naive_count_crossings(graph, north, south) { function dotest(mat) { const graph = reorder.mat2graph(mat, true), comps = graph.components(), - comp = comps.reduce((a, b) => { - return a.length > b.length ? a : b; - }); - comp.sort((a, b) => { - return a - b; - }); - const layer1 = comp.filter((n) => { - return graph.outEdges(n).length != 0; - }), - layer2 = comp.filter((n) => { - return graph.inEdges(n).length != 0; - }); + comp = comps.reduce((a, b) => a.length > b.length ? a : b); + comp.sort((a, b) => a - b); + const layer1 = comp.filter(n => graph.outEdges(n).length != 0), + layer2 = comp.filter(n => graph.inEdges(n).length != 0); //console.time('fast_crossings'); const c1 = reorder.count_crossings(graph, layer1, layer2); //console.timeEnd('fast_crossings'); @@ -97,12 +87,8 @@ suite.addBatch({ .directed(true) .init(), comp = graph.components()[0], - layer1 = comp.filter((n) => { - return graph.outEdges(n).length != 0; - }), - layer2 = comp.filter((n) => { - return graph.inEdges(n).length != 0; - }); + layer1 = comp.filter(n => graph.outEdges(n).length != 0), + layer2 = comp.filter(n => graph.inEdges(n).length != 0); assert.equal(naive_count_crossings(graph, layer1, layer2), 12); assert.equal(reorder.count_crossings(graph, layer1, layer2), 12); diff --git a/test/env-assert.js b/test/env-assert.js index ec997be..6d7225d 100644 --- a/test/env-assert.js +++ b/test/env-assert.js @@ -80,9 +80,7 @@ assert.inDeltaArrayAbs = (actual, expected, delta, message) => { }; function neg(a) { - return a.map((x) => { - return -x; - }); + return a.map(x => -x); } assert.inDeltaArrayOrNeg = (actual, expected, delta, message) => { diff --git a/test/graph2mat-test.js b/test/graph2mat-test.js index 9ce045f..b3ed802 100644 --- a/test/graph2mat-test.js +++ b/test/graph2mat-test.js @@ -12,9 +12,7 @@ function remove_zeroes(mat) { for (i = mat.length - 1; i >= 0; i--) { const row = mat[i]; if ( - row.some((a) => { - return a > 0; - }) + row.some(a => a > 0) ) { //console.log('remove row %d', i); break; @@ -23,9 +21,7 @@ function remove_zeroes(mat) { } for (j = mat[0].length - 1; j >= 0; j--) { if ( - mat.some((row) => { - return row[j] != 0; - }) + mat.some(row => row[j] != 0) ) { //console.log('remove column %d', j); break; diff --git a/test/order-test.js b/test/order-test.js index b951172..9193b36 100644 --- a/test/order-test.js +++ b/test/order-test.js @@ -430,15 +430,11 @@ function objEquiv(a, b) { } function toNum(a) { - return a.map((l) => { - return l.charCodeAt(0) - 97; - }); + return a.map(l => l.charCodeAt(0) - 97); } function toLetter(a) { - return a.map((l) => { - return String.fromCharCode(97 + l); - }); + return a.map(l => String.fromCharCode(97 + l)); } suite.export(module);