I have this
var nlist = [4,2,1,5];
var compare = (a, b) => a.compareTo(b);
nlist.sort(compare);
print(nlist); // [1,2,4,5]
and here (where I changed the (b, a)
to (a, b)
)
var nlist = [4,2,1,5]
var compare = (b, a) => a.compareTo(b);
nlist.sort(compare);
print(nlist); // [5,4,2,1]
Why does this little modification change from ascending to descending order?