diff --git a/package.json b/package.json index 0444e4b..094af14 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sorting-javascript", - "version": "1.0.3", + "version": "1.0.4", "description": "Sorting algorithms implemented in JS", "repository": "neeleshroy/sorting-js", "author": "Neelesh Roy", @@ -57,7 +57,6 @@ "coveralls": "cat ./coverage/lcov.info | coveralls", "build": "node tools/build", "prepublish": "npm run build", - "publish": "npm run build && npm publish dist", "publish:docs": "easystatic deploy docs --repo neeleshroy/sorting-js", "start": "easystatic start docs" } diff --git a/src/index.js b/src/index.js index a52fa97..542d3ee 100644 --- a/src/index.js +++ b/src/index.js @@ -2,10 +2,13 @@ import { ArrayTestBed } from './utils/ArrayTestBed'; import bubbleSort from './bubble-sort/index'; import insertionSort from './insertion-sort/index'; import selectionSort from './selection-sort/index'; +import { mergeSort } from './merge-sort/index'; + module.exports = { ArrayTestBed, bubbleSort, insertionSort, selectionSort, + mergeSort, }; diff --git a/src/quick-sort/index.js b/src/quick-sort/index.js new file mode 100644 index 0000000..4112be9 --- /dev/null +++ b/src/quick-sort/index.js @@ -0,0 +1,21 @@ +const quickSort = (arr) => { + const unsorted = arr; + + if (unsorted.length < 1) { + return unsorted; + } + + const pivot = unsorted[unsorted - 1]; + const left = []; + const right = []; + + for (let i = 0; i < unsorted.length - 1; i++) { + if (unsorted[i] < pivot) { + left.push(unsorted[i]); + } else { + right.push(unsorted[i]); + } + } + + return [...quickSort(left), pivot, ...quickSort(right)]; +};