Skip to content
This repository has been archived by the owner on Feb 20, 2019. It is now read-only.

First open source pull request! #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import snakeToCamel from './snake-to-camel'
import padLeft from './pad-left'
import randomInteger from './random-integer'
import arrayFill from './array-fill'
import sortArray from './sort-array.js'

export {
flatten,
Expand All @@ -12,4 +13,5 @@ export {
padLeft,
randomInteger,
arrayFill,
sortArray
}
23 changes: 23 additions & 0 deletions src/sort-array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export default sortArray

/**
* Original Source: http://stackoverflow.com/a/5476833/3316157
*
* This method will sort an array of values
*
* @param {Array} sortArray - the array to be sorted
* @param {String} dir - the sort direction ("asc" or "desc")
* @return {Array} - the sorted array
*/
function sortArray(sortArray, dir) {
if (dir == "asc") {
sortArray.sort(function(a, b) {
return a.toLowerCase() > b.toLowerCase()
});
} else {
sortArray.sort(function(a, b) {
return b.toLowerCase() > a.toLowerCase()
});
}
return sortArray;
}
16 changes: 16 additions & 0 deletions test/sort-array.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import test from 'ava'
import {sortArray} from '../src'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add your sortArray method to the src/index.js file. This is why the tests are failing.


test('sort an array of strings ascending', t => {
const original = ['apple','orange','peach','banana'];
const expected = ['apple','banana','orange','peach'];
const actual = sortArray(original,'asc')
t.same(actual, expected);
});

test('sort an array of strings descending', t => {
const original = ['apple','orange','peach','banana'];
const expected = ['peach','orange','banana','apple'];
const actual = sortArray(original,'desc');
t.same(actual, expected);
});