Skip to content

Commit

Permalink
localCompare can be used in custom functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jonschlinkert committed Jul 18, 2015
1 parent 86790ca commit b6bfe29
Showing 1 changed file with 1 addition and 13 deletions.
14 changes: 1 addition & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,12 @@ function sortBy(props, opts) {
*/

function compare(prop, a, b) {
// custom function
if (typeof prop === 'function') {
// expose `compare` to custom function
return prop(a, b, compare.bind(null, null));
}

// compare strings
if (typeof a === 'string' && typeof b === 'string') {
return a.localeCompare(b);
}

// compare numbers
if (typeOf(a) === 'number' && typeOf(b) === 'number') {
return a - b;
}

// compare object values
if (prop && typeOf(a) === 'object' && typeOf(b) === 'object') {
if (prop && typeof a === 'object' && typeof b === 'object') {
return compare(null, get(a, prop), get(b, prop));
}
return defaultCompare(a, b);
Expand Down

0 comments on commit b6bfe29

Please sign in to comment.