Sorting made sweet.
What is sugar-sorting?
Sugar-sorting is a NPM Module for sorting arrays. It's main goal is to provide a simple sorting API and many different sorting methods for the user to choose from. Sugar-sorting can make it easy for you to sort simple arrays and arrays of objects.
The first thing you should do is install the sugar-sorting module.
$ npm install -g sugar-sorting
Now you can use
require() to assign this module to a variable and start calling the module's methods.
var Sorter = ;var simpleArray = 2 4 6 3 1 5;var sorter = simpleArray;console;// --> [1, 2, 3, 4, 5, 6]
Sorting Arrays of Objects
Sugar-sorting also makes it easier for you to sort your arrays of objects by any property you want to. You just need to call the
var Sorter = ;var students =name: 'Stanley Kubrick'age: 50grades:highestGrade: 10lowestGrade: 8name: 'Christopher Nolan'age: 31grades:highestGrade: 85lowestGrade: 6name: 'Michael Bay'age: 37grades:highestGrade: 2lowestGrade: 0;var studentsSorter = students;var studentsByAge = studentsSorter;var studentsByHighestGrade = studentsSorter;
These are the sorting methods on sugar-sorting. The ones marked with an X are the ones available for use.
If you want to learn more about sorting algorithms and the best and worst case scenarios for each one, you can check these amazing links:
How sugar-sorting Works
When using sugar-sorting, imagine the Sorter object as a magic box in which you put in your array and then tell the box the way you want it to be sorted. After telling the box what you want it will sort your array. Now all you need to do is get the new sorted array from inside the box.
These are some basic steps to follow:
- Fill your sorter object using
var sorter = new Sorter(yourArray)or
- Tell the sorter object how you want it to be sorted. For example:
- Retrieve the sorted array from the sorter object using
You can contribute to sugar-sorting by writing tests, improving our algorithms or even creating new ones. Any improvement on the project's docs are welcome too!
To start developing just clone this repository and run the
npm install command on your terminal to download all the dev-dependencies.
If you find any bug or have any suggestion please tell us using our Issue Tracker.
After changing any line of code please run tests using
npm test or
Use it as you want to. No worries.
MIT © Lucas Fernandes da Costa