js-sortify
v1.1.1
Published
This package lets you sort your array in ascending or descending order with many different algorithms.
Maintainers
Readme
js-sortify Library
This npm package includes various sorting algorithms. Users can sort an array by providing an array and a sorting order (ascending - "asc" or descending - "desc").
Installation
npm install js-sortify
# or
yarn add js-sortifyUsage
Importing the Library:
const sortify = require("js-sortify"); // or import { quickSort, isSorted } from "js-sortify";Example Usage:
const sortedArray = sortify.quickSort(array, "asc"); // or const sortedArray = quickSort(array, "asc"); console.log(sortedArray);
Supported Sorting Algorithms
All functions below returns the sorted array
bubbleSort(array, sortOrder = 'asc')insertionSort(array, sortOrder = 'asc')selectionSort(array, sortOrder = 'asc')mergeSort(array, sortOrder = 'asc')quickSort(array, sortOrder = 'asc')heapSort(array, sortOrder = 'asc')radixSort(array, sortOrder = 'asc')shellSort(array, sortOrder = 'asc')cocktailSort(array, sortOrder = 'asc')bogoSort(array, sortOrder = 'asc')
Helper Functions
shuffle(array): Used to shuffle an array.isSorted(array, sortOrder): Checks if an array is sorted. (ReturnsTrueorFalse)
Parameters
- array (Array)
- sortOrder (String) -
'asc'or'desc'('asc'by default)
Contact
Feel free to reach out for any questions or suggestions.
- Email: [email protected]
