diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-04-02 13:08:06 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-04-02 13:08:06 -0400 |
| commit | c73e96ff916209d74e2be9bd7d8de3758685ce4d (patch) | |
| tree | 8f902fea5b6790061e48600243f0f8faeded32dd /test | |
| parent | b6534ce34706d1a98584e5f916107d91da072346 (diff) | |
Add comparison operator <> and array method to sort by a custom
comparison function
Diffstat (limited to 'test')
| -rw-r--r-- | test/arrays.tm | 12 | ||||
| -rw-r--r-- | test/tables.tm | 4 |
2 files changed, 14 insertions, 2 deletions
diff --git a/test/arrays.tm b/test/arrays.tm index e8856b3b..d4dd2119 100644 --- a/test/arrays.tm +++ b/test/arrays.tm @@ -73,3 +73,15 @@ if yes >> arr := [10, 20, 30] >> arr:reversed() = [30, 20, 10] + +if yes + >> nums := [10, -20, 30] + >> nums:sort() + >> nums + = [-20, 10, 30] + >> nums:sort(func(x:&%Int,y:&%Int) x:abs() <> y:abs()) + >> nums + = [10, -20, 30] + >> nums:sort(func(x:&%Int,y:&%Int) y[] <> x[]) + >> nums + = [30, 10, -20] diff --git a/test/tables.tm b/test/tables.tm index 53e81d48..74123f88 100644 --- a/test/tables.tm +++ b/test/tables.tm @@ -18,7 +18,7 @@ for k,v in t >> #t = 2 >> t.default -= ?(readonly)999 += ?%999 >> t.fallback = !{Text=>Int} @@ -42,7 +42,7 @@ for k,v in t >> t2.default = !Int >> t2.fallback -= ?(readonly){"one"=>1, "two"=>2; default=999} += ?%{"one"=>1, "two"=>2; default=999} t2_str := "" for k,v in t2 |
