Skip to content
Merged
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
9 changes: 8 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,11 @@ coverage

#editor settings
.idea
.editorconfig
.editorconfig

#core
src
docs
node_modules
test
tools
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ script:
- npm run lint
- npm run test:cover
after_success:
- npm run coveralls
- bump --minor --commit --tag
- npm run coveralls
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[![Build Status](https://travis-ci.org/NeeleshRoy/sorting-js.svg?branch=develop)](https://travis-ci.org/NeeleshRoy/sorting-js)
[![Coverage Status](https://coveralls.io/repos/github/NeeleshRoy/sorting-js/badge.svg?style=flat-square)](https://coveralls.io/github/NeeleshRoy/sorting-js)
[![dependencies Status](https://david-dm.org/neeleshroy/sorting-js/status.svg?style=flat-square)](https://david-dm.org/neeleshroy/sorting-js)
[![NPM](https://nodei.co/npm/sorting-javascript.png)](https://nodei.co/npm/sorting-javascript/)

> Sorting algorithms implemented in JS

Expand All @@ -16,7 +17,33 @@ $ npm install sorting-javascript

### Getting Started

ES6 - Use named imports
```javascript
import { insertionSort } from 'sorting-javascript'
insertionSort([7, 2, 5]) // Output - [2, 5, 7]
```

Node.JS require
```javascript
var sort = require('sorting-javascript')
sort.insertionSort([7, 2, 5]) // Output - [2, 5, 7]
```

There is an extra utility function called ArrayTestBed which generates random numbers
to test the sorting algorithms.
```javascript
import { ArrayTestBed } from 'sorting-javascript'
const test = new ArrayTestBed(1000);
test.setData() // test variable will have 1000 randomly generated numbers between 0-1000
```
By default, it will contain unique elements. If you pass random = false to the setData function, then the result will contain duplicates.
eg:
```javascript
test.setData(false) // [5, 6, 6, 8, 3, 2, 2]
test.setData() // [1, 7, 6, 8, 3, 2, 5]
```

## For Geeks :P
### How to Test

Run one, or a combination of the following commands to lint and test your code:
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sorting-javascript",
"version": "0.0.5",
"version": "1.0.1",
"description": "Sorting algorithms implemented in JS",
"repository": "neeleshroy/sorting-js",
"author": "Neelesh Roy",
Expand Down Expand Up @@ -30,7 +30,7 @@
"babel-eslint": "^6.0.4",
"babel-plugin-transform-runtime": "^6.8.0",
"babel-preset-es2015": "^6.6.0",
"babel-preset-es2015-rollup": "^1.1.1",
"babel-preset-es2015-rollup": "^3.0.0",
"babel-preset-stage-0": "^6.5.0",
"babel-register": "^6.8.0",
"bs-html-injector": "^3.0.3",
Expand Down
2 changes: 1 addition & 1 deletion src/bubble-sort/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import swap from '../utils/swap';

export function bubbleSort(unsorted, type = 'a') {
export default function (unsorted, type = 'a') {
if (unsorted.length === 0) return unsorted;
const r = unsorted;
let p = r.length;
Expand Down
11 changes: 9 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { ArrayTestBed } from './utils/ArrayTestBed';
import { bubbleSort } from './bubble-sort';
import bubbleSort from './bubble-sort/index';
import insertionSort from './insertion-sort/index';
import selectionSort from './selection-sort/index';

export default { ArrayTestBed, bubbleSort };
module.exports = {
ArrayTestBed,
bubbleSort,
insertionSort,
selectionSort,
};
2 changes: 1 addition & 1 deletion src/insertion-sort/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function insertionSort(arr) {
export default function (arr) {
const unsorted = arr;

for (let i = 1; i < unsorted.length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/selection-sort/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getMin, getMax } from '../utils/maxMin';

export function selectionSort(unsorted, type = 'a') {
export default function (unsorted, type = 'a') {
if (unsorted.length === 0) return unsorted;
const arr = unsorted;
const sorted = [];
Expand Down
2 changes: 1 addition & 1 deletion test/bubble-sort.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import { expect } from 'chai';
import { bubbleSort } from '../src/bubble-sort';
import bubbleSort from '../src/bubble-sort';

describe('Bubble Sort', () => {

Expand Down
2 changes: 1 addition & 1 deletion test/insertion-sort.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import { expect } from 'chai';
import { insertionSort } from '../src/insertion-sort';
import insertionSort from '../src/insertion-sort';

describe('Insertion Sort', () => {

Expand Down
2 changes: 1 addition & 1 deletion test/selection-sort.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import { expect } from 'chai';
import { selectionSort } from '../src/selection-sort';
import selectionSort from '../src/selection-sort';

describe('Selection Sort', () => {

Expand Down