Hi All,
I am having a list of months shuffled in a list. I want to arrange them in their chronological order. But I can sort only on alphabetical order. Help me guys.
local!months:{"June","January","March","Novemeber","February","October","December","April","July","May","September","August"}, sort(local!months).
Thank you
Discussion posts and replies are publicly visible
Turns out I can't resist a fun challenge...
a!localVariables( local!orderedMonthNames: a!forEach( enumerate(12), text(todate(fv!index & "/1/2021"), "mmmm") ), local!months: {"June", "January", "March", "Novemeber", "February", "October", "December", "April", "July", "May", "September", "August"}, local!mapped: a!forEach( local!months, a!map( name: fv!item, number: index(wherecontains(fv!item, local!orderedMonthNames), 1, -1) ) ), todatasubset( arrayToPage: local!mapped, pagingConfiguration: a!pagingInfo( startIndex: 1, batchSize: -1, sort: a!sortInfo( field: "number", ascending: true() ) ) ).data )
Me neither -)
a!localVariables( local!orderedMonthNames: a!forEach( enumerate(12), text(todate(fv!index & "/1/2021"), "mmmm") ), local!months: {"June", "January", "March", "November", "February", "October", "December", "April", "July", "May", "September", "August"}, reduce( a!update(_,_,_), {}, merge( a!forEach( items: local!months, expression: lookup(local!orderedMonthNames, fv!item) ), local!months ) ) )
Have an empty array and insert the strings at the correct index.
Huh, I actually didn't know about lookup() - that seems a little more civilized than having to call whereContains() (and flattened, as it were, using index()), when you just want to find a text value within an array.
Thanks that worked exactly how I want.
Thanks that works.
Also... I'd easily crawl through broken glass, or worse, suffer my code being 5 - 10 lines longer, to avoid having to use a nested reduce() / merge() combination... *shudder*