From 214b5af44981d0193eae01c8de49a10bae6a75a0 Mon Sep 17 00:00:00 2001 From: jonschlinkert Date: Fri, 17 Jul 2015 20:42:39 -0400 Subject: [PATCH] use `localeCompare` --- index.js | 4 ++-- test.js | 18 +++++++----------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index 510dcc2..306ea97 100644 --- a/index.js +++ b/index.js @@ -1,12 +1,12 @@ /*! * 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); }; \ No newline at end of file diff --git a/test.js b/test.js index 340acdb..d83826d 100644 --- a/test.js +++ b/test.js @@ -1,18 +1,14 @@ -/*! - * 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']); }); });