Browse files

returning the comparison function use case works

  • Loading branch information...
1 parent 936553d commit d33258cdbd8a147567dc492ed193b9260b2dc194 @substack committed Aug 24, 2012
Showing with 7 additions and 0 deletions.
  1. +7 −0 index.js
View
7 index.js
@@ -30,6 +30,13 @@ exports.descend = exports.fall = comparator(function (a, b) {
function comparator (cmp) {
return function (xs, f) {
+ if (typeof xs === 'function' || xs === undefined) {
+ f = xs || identity;
+ return function (a, b) {
+ return cmp({ x : f(a) }, { x : f(b) });
+ }
+ }
+
if (!f) f = identity;
var mapped = xs.map(function (x, i) {
return { i : i, x : f(x) };

0 comments on commit d33258c

Please sign in to comment.