Created
October 3, 2018 18:40
-
-
Save hillal20/6d2b86df7738e4ec2d2710a080af10c0 to your computer and use it in GitHub Desktop.
PeriodicLazyCoordinates created by hillal20 - https://repl.it/@hillal20/PeriodicLazyCoordinates
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
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