mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
builtin: fix sorting arrays of primitives (#8204)
This commit is contained in:
parent
190bb38087
commit
f059a9e96c
3 changed files with 80 additions and 67 deletions
|
@ -18,6 +18,25 @@ fn test_sorting_with_condition_expression() {
|
|||
assert a == sorted_desc
|
||||
}
|
||||
|
||||
fn test_sorting_primitives_with_condition_expression() {
|
||||
mut x := ['9', '87', '3210', '654']
|
||||
x.sort(a.len < b.len)
|
||||
assert x == ['9', '87', '654', '3210']
|
||||
}
|
||||
|
||||
fn get_score(word string) int {
|
||||
mut total := 0
|
||||
for letter in word {
|
||||
total += int(letter) - 97
|
||||
}
|
||||
return total
|
||||
}
|
||||
|
||||
fn test_sorting_with_fn_call_in_condition_expression() {
|
||||
mut words := ['aaaa', 'a', 'b', 'foo', 'bar']
|
||||
words.sort(get_score(a) < get_score(b))
|
||||
}
|
||||
|
||||
fn mysort(mut a []int) {
|
||||
a.sort()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue