Closed scottwater closed 4 years ago
Math.random()
returns a float between 0.0 and 1.0, so it probably won’t affect the default sort order. You could try something like subtracting 0.5 so you get a number between -0.5 and +0.5, per https://javascript.info/task/shuffle (click “solution” button).
Or, if you’re using nunjucks and want a single random element from an array/collection there is a random
filter.
That did the trick. Thanks for the tip and explanation.
Any suggestions for sorting a collection randomly?
I thought this would work:
But it is still sorting them alphabetically (no dates are available).
Thanks, Scott