|
@@ -108,7 +108,8 @@ func list_pop_at(l, i) {
|
|
|
return x
|
|
|
}
|
|
|
set_pseudomethod("list.popAt", list_pop_at)
|
|
|
-func list_sort(l, cmp=func (x, y): x > y) {
|
|
|
+func __cmp(x, y): x > y? 1: x < y? -1: 0
|
|
|
+func list_sort(l, cmp=__cmp) {
|
|
|
if type(l) != "list"
|
|
|
throw "expected first argument to be: list, but got: " + type(l)
|
|
|
if type(cmp) != "function"
|
|
@@ -118,14 +119,14 @@ func list_sort(l, cmp=func (x, y): x > y) {
|
|
|
var z = len(l)
|
|
|
for var i = 0; i < z - 1; i++
|
|
|
for var j = 0; j < z - 1 - i; j++
|
|
|
- if cmp(l[j], l[j+1]) {
|
|
|
+ if cmp(l[j], l[j+1]) > 0 {
|
|
|
let tmp = l[j]
|
|
|
l[j] = l[j+1]
|
|
|
l[j+1] = tmp
|
|
|
}
|
|
|
return l
|
|
|
}
|
|
|
-func list_sorted(l, cmp=func (x, y): x > y) {
|
|
|
+func list_sorted(l, cmp=__cmp) {
|
|
|
l = list_copy(l)
|
|
|
return list_sort(l, cmp)
|
|
|
}
|