ts-algorithm-utils
TypeScript icon, indicating that this package has built-in type declarations

0.0.72 • Public • Published

Algorithms Utils TS

A set of algorithms for your project.

Installation

yarn add ts-algorithm-utils
or
npm i ts-algorithm-utils

1. Sorting Algos

1.1 Quick Sort.

// import sort algo factory.
import {SortFactory, SortAlgo, Sort} from 'ts-algorithm-utils';
 
// set an unsorted array.
const arr = [9, 7, 5, 11, 12, 2, 14, 3, 10, 6];
 
// get the quick sort object from 
const sortAlgo: Sort<number> = SortFactory.make(SortAlgo.QUICK_SORT);
 
// sort the array.
const sorted = sortAlgo.sort(arr, 0, arr.length - 1);
 
// log the output.
console.log(sorted);

1.2 Merge Sort.

// import sort algo factory.
import {SortFactory, SortAlgo, Sort} from 'ts-algorithm-utils';
 
// set an unsorted array.
const arr = [9, 7, 5, 11, 12, 2, 14, 3, 10, 6];
 
// get the quick sort object from 
const sortAlgo: Sort<number> = SortFactory.make(SortAlgo.MERGE_SORT);
 
// sort the array.
const sorted = sortAlgo.sort(arr);
 
// log the output.
console.log(sorted);

1.3 Bubble Sort.

// import sort algo factory.
import {SortFactory, SortAlgo, Sort} from 'ts-algorithm-utils';
 
// set an unsorted array.
const arr = [9, 7, 5, 11, 12, 2, 14, 3, 10, 6];
 
// get the quick sort object from 
const sortAlgo: Sort<number> = SortFactory.make(SortAlgo.BUBBLE_SORT);
 
// sort the array.
const sorted = sortAlgo.sort(arr);
 
// log the output.
console.log(sorted);

1.4 Selection Sort.

// import sort algo factory.
import {SortFactory, SortAlgo, Sort} from 'ts-algorithm-utils';
 
// set an unsorted array.
const arr = [9, 7, 5, 11, 12, 2, 14, 3, 10, 6];
 
// get the quick sort object from 
const sortAlgo: Sort<number> = SortFactory.make(SortAlgo.SELECTION_SORT);
 
// sort the array.
const sorted = sortAlgo.sort(arr);
 
// log the output.
console.log(sorted);

1.5 Insertion Sort.

// import sort algo factory.
import {SortFactory, SortAlgo, Sort} from 'ts-algorithm-utils';
 
// set an unsorted array.
const arr = [9, 7, 5, 11, 12, 2, 14, 3, 10, 6];
 
// get the quick sort object from 
const sortAlgo: Sort<number> = SortFactory.make(SortAlgo.INSERTION_SORT);
 
// sort the array.
const sorted = sortAlgo.sort(arr);
 
// log the output.
console.log(sorted);

1.6 Radix Sort.

// import sort algo factory.
import {SortFactory, SortAlgo, Sort} from 'ts-algorithm-utils';
 
// set an unsorted array.
const arr = [9, 7, 5, 11, 12, 2, 14, 3, 10, 6];
 
// get the quick sort object from 
const sortAlgo: Sort<number> = SortFactory.make(SortAlgo.RADIX_SORT);
 
// sort the array.
const sorted = sortAlgo.sort(arr);
 
// log the output.
console.log(sorted);

Package Sidebar

Install

npm i ts-algorithm-utils

Weekly Downloads

2

Version

0.0.72

License

ISC

Unpacked Size

41.6 kB

Total Files

24

Last publish

Collaborators

  • codesmmith