tb-quicksort
TypeScript icon, indicating that this package has built-in type declarations

1.0.11 • Public • Published

Implementation of the quicksort algorithm in pure js/typescript function

var qs = require('tb-quickSort');
// typescript: import { quickSort } from 'tb-quickSort';
console.log(qs.quickSort([5, 3, 7, 5, 1]));
// -> [ 1, 3, 5, 5, 7 ]

If you want to provide your own algorithm or comparator:

var qs = require('tb-quickSort');
//typescript: import { quickSort } from 'tb-quickSort';
console.log(qs.quickSort([{a: 1}, {a: 3}, {a: 7}, {a:5}, {a:1}], function(value1, value2) {
  if (value1.a > value2.a) return -1;
  if (value2.a > value1.a) return 1;
  return 0;
}));
// -> [ {a: 1}, {a:1}, {a: 3}, {a:5}, {a: 7}]

Asynchronously

var qs = require('tb-quickSort');
//typescript: import { quickSortAsync } from 'tb-quickSort';
qs.quickSortAsync([5, 3, 7, 5, 1]).then(function(sortedArr) {
  console.log(sortedArr);
  // -> [ 1, 3, 5, 5, 7 ]
});

Readme

Keywords

Package Sidebar

Install

npm i tb-quicksort

Weekly Downloads

11

Version

1.0.11

License

MIT

Unpacked Size

9.62 kB

Total Files

5

Last publish

Collaborators

  • thangbui