diff --git a/index.js b/index.js index 91e23ca..01880e1 100644 --- a/index.js +++ b/index.js @@ -7,6 +7,7 @@ 'use strict'; +var defaultCompare = require('default-compare'); var typeOf = require('kind-of'); var get = require('get-value'); @@ -89,27 +90,6 @@ function compare(prop, a, b) { return defaultCompare(a, b); } -/** - * Default compare function used as a fallback - * for sorting. Built-in array sorting pushes - * null and undefined values to the end of the array. - */ - -function defaultCompare(a, b) { - var typeA = typeOf(a); - var typeB = typeOf(b); - - if (typeA === 'null') { - return typeB === 'null' ? 0 : (typeB === 'undefined' ? -1 : 1); - } else if (typeA === 'undefined') { - return typeB === 'null' ? 1 : (typeB === 'undefined' ? 0 : 1); - } else if (typeB === 'null' || typeB === 'undefined') { - return -1; - } else { - return a < b ? -1 : (a > b ? 1 : 0); - } -} - /** * Flatten the given array. */ diff --git a/package.json b/package.json index 3e3cffc..998e6d3 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "test": "mocha" }, "dependencies": { + "default-compare": "^1.0.0", "get-value": "^2.0.5", "kind-of": "^2.0.0" },