Skip to content

compare and sort functions added to runtime

Compare
Choose a tag to compare
@glenveegee glenveegee released this 08 Jun 13:58
· 7 commits to main since this release
  • compare two numbers or two strings to determine if they are equal (0), a > b (1) or b > a (-1)
  • sort an array using an optional function predicate for example:

Field-based sort

let data = [{'x': 6}, {'x': 1}, {'x': 3}]

let sorted = $sort($data, fn ($a, $b) { $compare($a.x, $b.x) });

Common case

let data = [6, 1, 3]

let sorted = $sort($data, $compare); // where compare takes strings or numbers

...or simply omit the $compare predicate to take advantage of builtin Array.sort behaviour