Skip to content

Commit

Permalink
use localeCompare
Browse files Browse the repository at this point in the history
  • Loading branch information
jonschlinkert committed Jul 18, 2015
1 parent 90105ee commit 214b5af
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*!
* sort-asc <https://github.com/helpers/sort-asc>
*
* Copyright (c) 2014 Jon Schlinkert, contributors.
* Copyright (c) 2014-2015 Jon Schlinkert.
* Licensed under the MIT License
*/

'use strict';

module.exports = function (a, b) {
return b < a ? -1 : 1;
return a === b ? 0 : a.localeCompare(b);
};
18 changes: 7 additions & 11 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
/*!
* sort-asc <https://github.com/jonschlinkert/sort-asc>
*
* Copyright (c) 2014 Jon Schlinkert, contributors.
* Licensed under the MIT License
*/

'use strict';

var assert = require('assert');
var sortAsc = require('./');

describe('sort object', function () {
it('should sort keys in ascending order.', function () {
var actual = (['a', 'b', 'c', 'd']).sort(sortAsc);
assert.deepEqual(actual, ['d', 'c', 'b', 'a']);
describe('sort ascending', function () {
it('should sort elements in ascending order.', function () {
assert.deepEqual(['d', 'c', 'b', 'a'].sort(sortAsc), ['a', 'b', 'c', 'd']);
assert.deepEqual(['g', 'z', 'a', 'x'].sort(sortAsc), ['a', 'g', 'x', 'z']);
assert.deepEqual(['z', 'z', 'a', 'z'].sort(sortAsc), ['a', 'z', 'z', 'z']);
assert.deepEqual(['zz', 'z', 'aa', 'a'].sort(sortAsc), ['a', 'aa', 'z', 'zz']);
assert.deepEqual(['aba', 'aab', 'acc', 'abb', 'aabb'].sort(sortAsc), ['aab', 'aabb', 'aba', 'abb', 'acc']);
});
});

0 comments on commit 214b5af

Please sign in to comment.