/sort-ts

Sorting algorithms for Typescript

Primary LanguageTypeScriptGNU General Public License v3.0GPL-3.0

sort-ts

build

Sorting algorithms for Typescript. All of the implemented algorithms are at the moment not-in-place ones, meaning they create and return a new array instead of mutating the original one.

Install

npm install sort-ts

Use

import {
  binaryTreeSort,
  bubbleSort,
  insertionSort,
  mergeSort,
  quickSort,
  selectionSort,
  shellSort
} from 'sort-ts';

// Compare function for ascending order
function compare(a: number, b: number): number {
  return a - b;
}

const orderedArray = bubbleSort([-1, 1, -100, 1000, 23, 34, 10000, 0], compare);
// Same for other algorithms

Contribute

Some algorithms could be added to the library. Feel free to add new ones and create a pull request!