Last active
November 16, 2018 18:51
-
-
Save a-x-/4b0607c6056cce93d44e7154f1be1b36 to your computer and use it in GitHub Desktop.
Stable Separation Sort. Move items below and above the pivot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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