README
sort.js
Simple JS library to sort different elements of an array
Install
npm i @wazabix/sort.js
API
- Constructor
new Sort ([array], [mode])
- function
.sortOption ([option], 'callback')
- Parameters
[mode]
[option]
[mode]
- Different possibilities: "numbers", "words" and "time"
- This parameters allows you to specify what type of data your table contains.
- Different possibilities: "numbers", "words" and "time"
[options]
- Differents possibilities: "descending", "ascending", "alphabetical", "reverse alphabetical order", "ordered" and "reverse ordered"
- This parameter allows you to define what kind of sort you want to have for your output array. In ascending or descending order, in alphabetical order or not if it's for words.
- Differents possibilities: "descending", "ascending", "alphabetical", "reverse alphabetical order", "ordered" and "reverse ordered"
Usage
[mode]
= numbers
Used to sort numbers in ascending or descending order
const { Sort } = require ('@wazabix/sort.js');
const numbers = [15, 4, 8, 25, 1];
new Sort (numbers, 'numbers').sortOption ('ascending', array => {
console.log (array);
});
// Expected output: [ 1, 4, 8, 15, 25 ]
// ------------------------------------------------------
new Sort (numbers, 'numbers').sortOption ('descending', array => {
console.log (array);
});
// Expected output: [ 25, 15, 8, 4, 1 ]
[mode]
= words
Used to sort words in alphabetical or non-alphabetical order
const { Sort } = require ('@wazabix/sort.js');
const words = ['mango', 'pineapple', 'kiwi', 'fruits'];
new Sort (words, 'words').sortOption ('alphabetical', array => {
console.log (array);
});
// Expected output: [ 'fruits', 'kiwi', 'mango', 'pineapple' ]
// ----------------------------------------------------------------
new Sort (words, 'words').sortOption ('reverse alphabetical order', array => {
console.log (array);
});
// Expected output: [ 'pineapple', 'mango', 'kiwi', 'fruits' ]
[mode]
= time
Used to sort the different times of the day
All times of the day are taken care of
You can see them in this picture: https://www.englishlearnsite.com/wp-content/uploads/2018/01/Times-of-The-Day.jpg
const { Sort } = require ('@wazabix/sort.js');
const wordsTime = ['night', 'morning', 'afternoon', 'early afternoon', 'noon', 'midnight'];
new Sort (wordsTime, 'time').sortOption ('ordered', array => {
console.log (array);
});
/* Expected output: [
'morning',
'noon',
'early afternoon',
'afternoon',
'night',
'midnight'
]
*/
// ------------------------------------------------------------------------------
new Sort (wordsTime, 'time').sortOption ('reverse ordered', array => {
console.log (array);
});
/* Expected output: [
'midnight',
'night',
'afternoon',
'early afternoon',
'noon',
'morning'
]
*/