From cd4029dc6150c1406abfcf96878d6d9e52b0e0e4 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 3 Sep 2014 09:32:09 -0700 Subject: [PATCH] Make `_.sortBy` move`undefined` and `NaN` to the end of the array. --- lodash.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lodash.js b/lodash.js index bb17b4e59..2e950feec 100644 --- a/lodash.js +++ b/lodash.js @@ -331,10 +331,13 @@ */ function baseCompareAscending(value, other) { if (value !== other) { - if (value > other || typeof value == 'undefined') { + var valIsReflexive = value === value, + othIsReflexive = other === other; + + if (value > other || !valIsReflexive || (typeof value == 'undefined' && othIsReflexive)) { return 1; } - if (value < other || typeof other == 'undefined') { + if (value < other || !othIsReflexive || (typeof other == 'undefined' && valIsReflexive)) { return -1; } }