From 775333719de574735454ca2a9b0ce5187b43dbaf Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Mar 2018 14:42:57 +0100 Subject: [PATCH] Shuffle instances --- themes/hugo-bootstrap-premium/static/js/instances.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/themes/hugo-bootstrap-premium/static/js/instances.js b/themes/hugo-bootstrap-premium/static/js/instances.js index 4f7a215..b60a040 100644 --- a/themes/hugo-bootstrap-premium/static/js/instances.js +++ b/themes/hugo-bootstrap-premium/static/js/instances.js @@ -10,7 +10,7 @@ $(function () { $.get(instancesApi, data) .done(function (res) { - const instances = res.data + const instances = shuffle(res.data) const lis = [] instances.forEach(function (instance) { @@ -80,4 +80,14 @@ $(function () { return a } + + // Thanks https://stackoverflow.com/a/6274381 + function shuffle (a) { + for (var i = a.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [a[i], a[j]] = [a[j], a[i]] + } + + return a + } })