Skip to content

Instantly share code, notes, and snippets.

@ttezel
Created July 16, 2012 19:10
Show Gist options
  • Select an option

  • Save ttezel/3124434 to your computer and use it in GitHub Desktop.

Select an option

Save ttezel/3124434 to your computer and use it in GitHub Desktop.
Simple QuickSort in JS
function quickSort (arr) {
if (!arr.length)
return arr
var pivot = arr.splice(0, 1)
var less = []
var greater = []
arr.forEach(function (el) {
if (el <= pivot)
less.push(el)
else
greater.push(el)
})
return quickSort(less).concat(pivot, quickSort(greater))
}
var test = [ 1, 7, 3, 6, 8, 9, 10, 45, 23, 54, 4, 3 ]
var sorted = quickSort(test)
console.log('sorted', sorted)
@DennyDaVjncj

DennyDaVjncj commented Sep 28, 2021

Copy link
Copy Markdown

Great question @zero-t4, I'm curious about that too

@Ian-kensington-chadwick-the-3rd

Copy link
Copy Markdown

your code is my study material in 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment