Skip to content

Instantly share code, notes, and snippets.

@a-x-
Last active November 16, 2018 18:51
Show Gist options
  • Save a-x-/4b0607c6056cce93d44e7154f1be1b36 to your computer and use it in GitHub Desktop.
Save a-x-/4b0607c6056cce93d44e7154f1be1b36 to your computer and use it in GitHub Desktop.
Stable Separation Sort. Move items below and above the pivot
const arr = [
14418,
584,
1108,
1020,
363,
7073,
]
const max = Math.max(...arr)
const pivot = .3; // 30%
arr.sort((a,b) => {
const isNormalA = a / max >= pivot;
const isNormalB = b / max >= pivot;
if (isNormalA === isNormalB) return 0
if (isNormalA) return -1;
if (isNormalB) return +1;
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment