node-sortable is a library that implements various sorting algorithms and displays its performance according to BIG -O notation.
In computer science, big O notation is used to classify algorithms by how they respond to changes in input size, such as how the processing time of an algorithm changes as the problem size becomes extremely large.
Algorithm | Status |
---|---|
Quick | DONE |
Merge | DONE |
Comb | DONE |
Time | TODO |
Heap | DONE |
Bubble | DONE |
Insertion | DONE |
Selection | DONE |
Tree | TODO |
Shell | DONE |
Bucket | DONE |
Radix | DONE |
Counting | TODO |
Cube | TODO |
Verify if you have node and npm installed.
npm i node-sortable
const sort = require('node-sortable');
sort.comb(array, sort.DESC)
sort.comb(array, sort.ASC)
sort.comb(array, comparisonFunction)
sort.quick(array, sort.DESC)
sort.quick(array, sort.ASC)
sort.quick(array, comparisonFunction)
sort.merge(array, sort.DESC)
sort.merge(array, sort.ASC)
sort.merge(array, comparisonFunction)
sort.selection(array, sort.DESC)
sort.selection(array, sort.ASC)
sort.selection(array, comparisonFunction)
sort.bubble(array, sort.DESC)
sort.bubble(array, sort.ASC)
sort.bubble(array, comparisonFunction)
sort.insertion(array, sort.DESC)
sort.insertion(array, sort.ASC)
sort.insertion(array, comparisonFunction)
sort.bucket(array, bucketSize, sort.DESC)
sort.bucket(array, bucketSize, sort.ASC)
sort.bucket(array, bucketSize, comparisonFunction)
sort.shell(array, sort.DESC)
sort.shell(array, sort.ASC)
sort.shell(array, comparisonFunction)
sort.heap(array, sort.DESC)
sort.heap(array, sort.ASC)
βοΈ Example how to use:
let numbers = [10, 1, 2, 13];
sort.method(numbers, sort.ASC); //[1,2,10,13]
sort.method(numbers, sort.DESC); //[13,10,2,1]
let letters = ["A","Z","W","M"];
sort.method(letters, sort.ASC); //["A","M","W","Z"]
sort.method(letters, sort.DESC); //["Z","W","M","A"]
βοΈ Example customized comparison function:
let peoples = [
{name: "Alex", age: 12},
{name: "Max", age: 34},
{name: "Mary", age: 9},
{name: "Justin", age: 53}
];
const fnASC = (a, b) =>{
return a.age > b.age; //inverse of the natural condition
}
const fnDESC = (a, b) =>{
return a.age < b.age; //inverse of the natural condition
}
sort.bubble(peoples, fnASC); //[{name: "Mary", age: 9}, {name: "Alex", age: 12},{name: "Max", age: 34},{name: "Justin", age: 53}];
sort.bubble(peoples, fnDESC); //[{name: "Justin", age: 53},{name: "Max", age: 34},{name: "Alex", age: 12},{name: "Mary", age: 9}];
sort.radix(array, significant_digit);
βοΈ Radix Example:
- Input list:
let array = [126, 328, 636, 341, 416, 131, 328]
sort.radix(array, 1);
Least significant digit output: 341, 131, 126, 636, 416, 328, 328
sort.radix(array, 2);
Next high significant digit output: 416, 126, 328, 328, 131, 636, 341
sort.radix(array, 3);
Most significant digit output: 1 26, 131, 328, 328, 341, 416, 636
Follow the node-sortable style guide.
Validate the code style with ESLint:
npm run eslint
Generate code docs with JSDocs:
npm run jsdocs
View code docs in docs/index.html
Run the unit tests with mocha:
npm run test
Calculate the coverage with Istanbul:
npm run cover
To keep better organization of releases we follow the Semantic Versioning 2.0.0 guidelines.
Find on our issues the next steps of the project ;) Want to contribute? Follow these recommendations.
The MIT License (MIT)
Copyright (c) 2016 FΓ‘bio Pereira
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.