Skip to content

Commit 85a6da4

Browse files
committed
Add sorting of the list of running nodes by public key.
1 parent 23842d7 commit 85a6da4

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/pages/Index.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,7 @@ export default {
810810
}
811811
}
812812
this.nodes = utils.getUnique(this.nodes, 'key')
813+
this.nodes = utils.sortByKey(this.nodes, 'key')
813814
resolve()
814815
}).catch((error) => {
815816
console.log(error)

src/util/utils.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,22 @@ function getUnique (arr, comp) {
1919
return unique
2020
}
2121

22+
/**
23+
* Sort array of object by key field
24+
*
25+
* @param {*} array
26+
* @param {*} key
27+
* @returns {Array} Sorted Array
28+
*/
29+
function sortByKey (array, key) {
30+
return array.sort(function (a, b) {
31+
var x = a[key]
32+
var y = b[key]
33+
return ((x < y) ? -1 : ((x > y) ? 1 : 0))
34+
})
35+
}
36+
2237
export {
23-
getUnique
38+
getUnique,
39+
sortByKey
2440
}

0 commit comments

Comments
 (0)