Created
February 7, 2020 09:33
-
-
Save WietseWind/7a66a4fa79a654c079b330d121ca8b37 to your computer and use it in GitHub Desktop.
Sort on custom attr. + rippled version sort
This file contains 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 fetch = require('node-fetch') | |
const rippledVersionForSorting = v => { | |
const vArray = v.split('-')[1].split('.') | |
if (vArray.length === 3) { | |
return vArray[0] * 100000 // Major | |
+ vArray[1] * 1000 // Minor | |
+ vArray[2] * 10 // Patch | |
+ Number((v.split('-')[2] || '').replace(/[^0-9]/g, '')) // RC/Beta | |
} | |
return 0 | |
} | |
let topologyData = undefined | |
fetch ('https://data.ripple.com/v2/network/topology/').then(r => r.json()).then(data =>{ | |
const sortedNodes = data.nodes.sort((a, b) => rippledVersionForSorting(a.version) - rippledVersionForSorting(b.version)) | |
topologyData = { | |
...data, | |
nodes: sortedNodes | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment