Greetings!
Does anyone have a clever way to output a bulleted list in randomized order?
Greetings!
Does anyone have a clever way to output a bulleted list in randomized order?
@Sean_P_O_MacCath-Mor, can you tell me a bit more about how you would want to use this workflow please?
You bet!
Let's say you have a list of items, and you want to output them in a random order:
{resources=[
"The 30-Day Vegan Challenge":"http://www.the30dayveganchallenge.com/",
"Challenge 22":"https://www.challenge22.com/",
"One Ingredient Chef":"http://www.oneingredientchef.com/",
"The VeganStreet Guide for New Vegans":"http://veganstreet.com/guidefornewvegans.html",
"The Plantpower Meal Planner":"http://www.richroll.com/blog/no-more-excuses/"
]}
{resource_keys=keys(resources)} <-- randomize resource_keys
order somehow?
{repeat: for key in resource_keys}
-> {=key}: {=resources[key]}
{endrepeat}
It's a bit complex, but you can do it by sorting on a random number. I've implemented this in a reusable function below.
{randomizelist=(list) -> map(sort(map(list, x -> ["id":random(), "value":x]), (a,b) -> a.id - b.id), x -> x.value)}
{=randomizelist(["aaa", "bbb", "ccc", "ddd"])}
{=randomizelist(["aaa", "bbb", "ccc", "ddd"])}
{=randomizelist(["aaa", "bbb", "ccc", "ddd"])}
{=randomizelist(["aaa", "bbb", "ccc", "ddd"])}
{=randomizelist(["aaa", "bbb", "ccc", "ddd"])}
@scott, that is a bit of elegant genius, that is. Works a treat. Thank you VERY much!