Created
November 23, 2016 21:54
-
-
Save dividead/b801adebf0e87908f0f56bf49e46b095 to your computer and use it in GitHub Desktop.
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
function q(a){ | |
if(a.length <= 1) return a | |
let p = a.shift() //or pop | |
let left = a.filter(e => e <= p) // or in one interation | |
let right = a.filter(e => e > p) | |
return [...q(left), p, ...q(right)] | |
} | |
console.log(q([2,6,7,1,4,9,3,5])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment