Created
May 5, 2019 04:25
-
-
Save vladanyes/83a07193bfb91846ddb73b49399ff842 to your computer and use it in GitHub Desktop.
Quicksort in JavaScript
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 arrayToSort = [1,9,2,8,3,7,4,6,5]; | |
const sort = array => { | |
if (array.length < 2) return array; | |
const [pivot, ...restItems] = array; | |
const less = [...restItems].filter(item => item < pivot); | |
const greater = [...restItems].filter(item => item > pivot); | |
console.log('test'); | |
return sort(less).concat(pivot).concat(sort(greater)); | |
}; | |
console.log(sort(arrayToSort)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment