builtin: support also [abc,def].sort(b>a)

pull/6516/head
Delyan Angelov 2020-10-06 21:32:32 +03:00
parent f7decfe399
commit ce302c29e4
2 changed files with 23 additions and 0 deletions

View File

@ -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

View File

@ -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)