comb-sort

0.1.2 • Public • Published

CombSort implementation on javascript.

See: https://en.wikipedia.org/wiki/Comb_sort

Install:

npm i comb-sort

or

yarn add comb-sort

Basic usage:

const data = [some...data]
const sortedData = combSort(data)

(This is mutable operation and it will change source array)

or

const sortedData = combSort(data.slice())

You can pass a custom compare function as the second argument:

const customCompare = (first, second) => {
  if (
    Array.isArray(first.children) &&
    Array.isArray(second.children) &&
    first.children.length > second.children.length
  ) {
    return true
  }
  return false
}
const sortedData = combSort(data, customCompare)

Also, you can pass custom reduction value as the third argument.

const sortedData = combSort(data, customCompare, 1.8)

Be careful with playing with reduction parameter.

It can affect performance and accuracy.

Package Sidebar

Install

npm i comb-sort

Weekly Downloads

1

Version

0.1.2

License

MIT

Unpacked Size

9.52 kB

Total Files

14

Last publish

Collaborators

  • mbalabash