node-sortable 🚀😄
📌 What is that ?
node-sortable is a library that implements various sorting algorithms and displays its performance according to BIG -O notation.
📌 Big-O Complexity Chart
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.
📌 Roadmap
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 |
📌 How to install
Verify if you have node and npm installed.
✅ Run:
npm install node-sortable --save
const sort = require('node-sortable');
📌 Methods
✅ Comb Sort
sort.comb(array, sort.DESC)
sort.comb(array, sort.ASC)
sort.comb(array, comparisonFunction)
✅ Quick Sort
sort.quick(array, sort.DESC)
sort.quick(array, sort.ASC)
sort.quick(array, comparisonFunction)
✅ Merge Sort
sort.merge(array, sort.DESC)
sort.merge(array, sort.ASC)
sort.merge(array, comparisonFunction)
✅ Selection Sort
sort.selection(array, sort.DESC)
sort.selection(array, sort.ASC)
sort.selection(array, comparisonFunction)
✅ Bubble Sort
sort.bubble(array, sort.DESC)
sort.bubble(array, sort.ASC)
sort.bubble(array, comparisonFunction)
✅ Insertion Sort
sort.insertion(array, sort.DESC)
sort.insertion(array, sort.ASC)
sort.insertion(array, comparisonFunction)
✅ Bucket Sort
⚠️ This implementation only supports integers
sort.bucket(array, bucketSize, sort.DESC)
sort.bucket(array, bucketSize, sort.ASC)
sort.bucket(array, bucketSize, comparisonFunction)
✅ Shell Sort
⚠️ This implementation only supports integers
sort.shell(array, sort.DESC)
sort.shell(array, sort.ASC)
sort.shell(array, comparisonFunction)
✅ Heap Sort
⚠️ This implementation only supports numbers
sort.heap(array, sort.DESC)
sort.heap(array, sort.ASC)
✏️ Example how to use:
let numbers = 10 1 2 13; sortmethodnumbers sortASC; //[1,2,10,13]sortmethodnumbers sortDESC; //[13,10,2,1] let letters = "A""Z""W""M";sortmethodletters sortASC; //["A","M","W","Z"]sortmethodletters sortDESC; //["Z","W","M","A"]
✏️ Example customized comparison function:
⚠️ Important Note: Some comparison conditions are the reverse of the natural because this way the algorithm takes best advantage. Before implementing a custom comparison function check the operation of the algorithm. It is very suitable to use drive tests.
let peoples = name: "Alex" age: 12 name: "Max" age: 34 name: "Mary" age: 9 name: "Justin" age: 53; const fnASC = { return aage > bage; //inverse of the natural condition} const fnDESC = { return aage < bage; //inverse of the natural condition} sort; //[{name: "Mary", age: 9}, {name: "Alex", age: 12},{name: "Max", age: 34},{name: "Justin", age: 53}];sort; //[{name: "Justin", age: 53},{name: "Max", age: 34},{name: "Alex", age: 12},{name: "Mary", age: 9}];
✅ Radix Sort
sort.radix(array, significant_digit);
✏️ Radix Example:
⚠️ This implementation only supports integers
- 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
📌 Development
Code style:
Follow the node-sortable style guide.
Validate the code style with ESLint:
npm run eslint
Code Docs
Generate code docs with JSDocs:
npm run jsdocs
View code docs in docs/index.html
Tests
Run the unit tests with mocha:
npm run test
Calculate the coverage with Istanbul:
npm run cover
📌 Versioning
To keep better organization of releases we follow the Semantic Versioning 2.0.0 guidelines.
📌 Contributing
Find on our issues the next steps of the project ;) Want to contribute? Follow these recommendations.
📌 License
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.