builtin: support also [abc,def].sort(b>a)
parent
f7decfe399
commit
ce302c29e4
|
@ -1014,6 +1014,16 @@ pub fn compare_strings(a, b &string) int {
|
|||
return 0
|
||||
}
|
||||
|
||||
fn compare_strings_reverse(a, b &string) int {
|
||||
if a.lt(b) {
|
||||
return 1
|
||||
}
|
||||
if a.gt(b) {
|
||||
return -1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
fn compare_strings_by_len(a, b &string) int {
|
||||
if a.len < b.len {
|
||||
return -1
|
||||
|
|
|
@ -99,6 +99,19 @@ fn test_sort() {
|
|||
assert vals[3] == 'arr'
|
||||
}
|
||||
|
||||
fn test_sort_reverse() {
|
||||
mut vals := [
|
||||
'arr', 'an', 'a', 'any'
|
||||
]
|
||||
len := vals.len
|
||||
vals.sort(b>a)
|
||||
assert len == vals.len
|
||||
assert vals[3] == 'a'
|
||||
assert vals[2] == 'an'
|
||||
assert vals[1] == 'any'
|
||||
assert vals[0] == 'arr'
|
||||
}
|
||||
|
||||
fn test_split_nth() {
|
||||
a := "1,2,3"
|
||||
assert (a.split(',').len == 3)
|
||||
|
|
Loading…
Reference in New Issue