diff --git a/vlib/builtin/string.v b/vlib/builtin/string.v index fc75c7ebf4..cca6a772f9 100644 --- a/vlib/builtin/string.v +++ b/vlib/builtin/string.v @@ -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 diff --git a/vlib/builtin/string_test.v b/vlib/builtin/string_test.v index 613156fcb0..69684973d8 100644 --- a/vlib/builtin/string_test.v +++ b/vlib/builtin/string_test.v @@ -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)