1.0.1 • Published 2 years ago

merge-sort-nat v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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-nat

Yarn

yarn add merge-sort-nat

Currently 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 console

Documentation:

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 install

or

yarn
  • Run test command
npm test

or

yarn test

License: MIT

Author: Zulpykhar Azamat

Group: CS2005

Astana IT University 2020-2023