SORTBY
lists
gts
The SORTBY
function sorts a LIST or a MAP according to a value returned by a macro. The macro must return a value of the same type (LONG, DOUBLE or STRING) for each element.
Only MAPs of type LinkedHashMap, which are the most commons in WarpScript, can be sorted.
Before release 1.2.22
, the SORTBY
function could only sort lists of Geo Time Series™.
Before release 2.7.0
, the SORTBY
function could only sort lists but not maps.
SORTBY is available since version 1.0.11.
See also
Signatures
Examples
//
// Create 3 Geo Time Series
//
1 3
<%
NEWGTS
SWAP TOSTRING RENAME
1 100
<%
NaN NaN NaN RAND ADDVALUE
%>
FOR
%>
FOR
3 ->LIST
// Add mean and std as attributes, only here to check the result.
<%
DROP
DUP false MUSIGMA [ 'mu' 'sigma' ] STORE
{ 'mu' $mu TOSTRING 'sigma' $sigma TOSTRING } SETATTRIBUTES
%>
LMAP
//
// Sort the GTS according to their mean
//
<%
false MUSIGMA DROP
%>
SORTBY
{
'bob' 1337
'john' 42
'anna' 777
}
<%
SWAP DROP // Sort on value
%>
SORTBY