Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

mbalabash/comb-sort

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

CombSort implementation on javascript.

Resources

License

Stars

Watchers

Forks

Packages

No packages published