Created
August 31, 2020 00:48
-
-
Save MichaelDimmitt/a7168c259baff7c4eb3e396de3b4b093 to your computer and use it in GitHub Desktop.
Lets me make graphs sequentially or with an air or randomness for highcharts https://www.highcharts.com/docs/chart-and-series-types/network-graph
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const alphabet = [ | |
'a', 'b', 'c', 'd', 'e','f','g','h','i','j','k','l','m', | |
'n','o','p','q','r','s','t','u','v','w','x','y','z' | |
] | |
const deepCopyAlphabet = () => JSON.parse(JSON.stringify(alphabet)); | |
const getRandomInt = (arr) => Math.floor((Math.random() * arr.length)) | |
let mainGraph = [] | |
const connectNodesByNumber = ({letter, num, arr, mainGraph, isRandom}) => { | |
const alphabetValue = isRandom ? getRandomInt(arr) : num | |
const [removed] = arr.splice(alphabetValue, 1) | |
mainGraph.push([letter, removed]) | |
if(num > 1){ | |
return connectNodesByNumber({letter, num: --num, arr, mainGraph, isRandom}) | |
} | |
else { return mainGraph } | |
} | |
connectNodesByNumber({letter: 'a', num: 20, arr: deepCopyAlphabet(), mainGraph, isRandom: true}) | |
connectNodesByNumber({letter: 'b', num: 20, arr: deepCopyAlphabet(), mainGraph, isRandom: false}) | |
console.log(JSON.stringify(mainGraph)) | |
/* example output: | |
[ | |
["a","h"],["a","y"],["a","d"],["a","v"],["a","w"],["a","r"],["a","l"],["a","i"],["a","f"],["a","s"], | |
["a","j"],["a","m"],["a","e"],["a","t"],["a","k"],["a","a"],["a","x"],["a","z"],["a","b"],["a","n"], | |
["b","u"],["b","t"],["b","s"],["b","r"],["b","q"],["b","p"],["b","o"],["b","n"],["b","m"],["b","l"], | |
["b","k"],["b","j"],["b","i"],["b","h"],["b","g"],["b","f"],["b","e"],["b","d"],["b","c"],["b","b"] | |
] | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment