1.0.1 • Published 4 years ago
merge-sort-nat v1.0.1
Merge sort library
Merge sort algorithm implementation in node.js and typescript
To install run following command in your terminal:
Npm
npm install merge-sort-natYarn
yarn add merge-sort-natCurrently works only in node environment
Get starting example:
const { mergeSort } = require("merge-sort-nat"); // Import function
let array = [5, 4, 3, 2, 1]; // Create array
let sortedArray = mergeSort(array, (a, b) => a - b); // Sort array in ascending order
console.log(sortedArray); // Display result in consoleDocumentation:
mergeSort
Function that takes array and returns new sorted array
Parameters:
array:T[]
Array that we need to sort
compareFunction:(firstElement: T,secondElement: T) => number
Function that takes two elements and changes their order basing on output of function:
If output number is below 0, it takes firstElement
If output number is above 0, it takes secondElement
If output number is equal 0, it does not change order of elements
Tests
Tests implemented in jest and located in __tests__ folder
To run tests locally:
- Clone repository
git clone https://github.com/amazzat/merge-sort.git zulpykhar_azamat_cs2005_merge_sort- Enter the folder
cd ./zulpykhar_azamat_cs2005_merge_sort- Install packages
npm installor
yarn- Run test command
npm testor
yarn test