Skip to content

Commit

Permalink
sort
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenGrider committed Jun 13, 2020
1 parent 3e0bd03 commit d54761e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
20 changes: 20 additions & 0 deletions exercises/sorting/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// --- Directions
// Implement bubbleSort, selectionSort, and mergeSort

function bubbleSort(arr) {

}

function selectionSort(arr) {

}

function mergeSort(arr) {

}

function merge(left, right) {

}

module.exports = { bubbleSort, selectionSort, mergeSort };
30 changes: 30 additions & 0 deletions exercises/sorting/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const S = require('./index');
const bubbleSort = S.bubbleSort;
const selectionSort = S.selectionSort;
const mergeSort = S.mergeSort;

function getArray() {
return [100, -40, 500, -124, 0, 21, 7];
}

function getSortedArray() {
return [-124, -40, 0, 7, 21, 100, 500];
}

describe('Bubble sort', () => {
test('sorts an array', () => {
expect(bubbleSort(getArray())).toEqual(getSortedArray());
});
});

describe('Selection sort', () => {
test('sorts an array', () => {
expect(selectionSort(getArray())).toEqual(getSortedArray());
});
});

describe('Merge sort', () => {
test('sorts an array', () => {
expect(mergeSort(getArray())).toEqual(getSortedArray());
});
});

0 comments on commit d54761e

Please sign in to comment.