Using Javascript with Underscore.js to Sort the other way
Instead of throwing underscorejs away, I'd rather use it together with Array.reverse
to utilize the best of both.
_.sortBy(["Bob", "Mary", "Alice"], function (name) {return name})
.reverse()
I would just do what Underscore does under the hood: use the Array#sort method.
["Bob", "Mary", "Alice"].sort(function (a, b) {
if (a < b) return 1;
if (b < a) return -1;
return 0;
});
Or if you don't want the original array modified, clone it first:
_.clone(["Bob", "Mary", "Alice"]).sort(...)