0.1.2 • Published 5 years ago

comb-sort v0.1.2

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

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.