From d6cd367b251500124e05bb4e030e8124364107b0 Mon Sep 17 00:00:00 2001 From: Rodrigo Date: Sat, 23 Jan 2021 15:56:09 -0300 Subject: [PATCH 1/2] Added density calculation --- Graphs/Density.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Graphs/Density.js diff --git a/Graphs/Density.js b/Graphs/Density.js new file mode 100644 index 000000000..b2a549858 --- /dev/null +++ b/Graphs/Density.js @@ -0,0 +1,11 @@ +/* +The density of a network is a measure of how many edges exist proportional to +how many edges would exist in a complete network (where all possible edges). +https://networkx.org/documentation/networkx-1.9/reference/generated/networkx.classes.function.density.html +*/ +function density (numberOfNodes, numberOfEdges, isDirected = false) { + const multi = isDirected ? 1 : 2 + return (multi * numberOfEdges) / (numberOfNodes * (numberOfNodes - 1)) +} + +(() => { console.log(density(10, 2)) })() From 493aab430944cfc238e46975f510457bc8916b93 Mon Sep 17 00:00:00 2001 From: Rodrigo Morais <58960796+rodigu@users.noreply.github.com> Date: Tue, 2 Feb 2021 16:54:14 -0300 Subject: [PATCH 2/2] Removed anonymous function --- Graphs/Density.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Graphs/Density.js b/Graphs/Density.js index b2a549858..116fb8e40 100644 --- a/Graphs/Density.js +++ b/Graphs/Density.js @@ -8,4 +8,4 @@ function density (numberOfNodes, numberOfEdges, isDirected = false) { return (multi * numberOfEdges) / (numberOfNodes * (numberOfNodes - 1)) } -(() => { console.log(density(10, 2)) })() +console.log(density(10, 2))