See: https://en.wikipedia.org/wiki/Comb_sort
npm i comb-sort
or
yarn add comb-sort
const data = [some...data]
const sortedData = combSort(data)
(This is mutable operation and it will change source array)
or
const sortedData = combSort(data.slice())
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)
const sortedData = combSort(data, customCompare, 1.8)
Be careful with playing with reduction parameter.
It can affect performance and accuracy.