Skip to content

Instantly share code, notes, and snippets.

@hillal20
Created October 3, 2018 18:40
Show Gist options
  • Save hillal20/6d2b86df7738e4ec2d2710a080af10c0 to your computer and use it in GitHub Desktop.
Save hillal20/6d2b86df7738e4ec2d2710a080af10c0 to your computer and use it in GitHub Desktop.
PeriodicLazyCoordinates created by hillal20 - https://repl.it/@hillal20/PeriodicLazyCoordinates
let arr = [100,1,50,2,3,4,7,2,10,5,2,1,20,13]
function quickSort(arr){
if(arr.length <= 1 ){
return arr
}
let pivote = arr[arr.length - 1];
let right = [];
let left = [];
for ( let i = 0; i < arr.length - 1 ;i ++){
if( arr[i] < pivote){
left.push(arr[i])
}
else{
right.push(arr[i])
}
}
return [ ...quickSort(left), pivote, ...quickSort(right)]
}
quickSort(arr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment