//Define a quick Sort methodfunctionQuickSort (arr) {
//set the termination criteria for recursion if(Arr.length <= 1){ returnarr; } //gets the values of the intermediate and intermediate indexes of the array arr varMiddlenum = Math.floor (ARR.LENGTH/2);varMiddlevalue = Arr.splice (Middlenum, 1); //defines the array, left to hold the number less than the middle value, right to hold the number greater than the middle value varleft = []; varright = []; //iterates through the ARR array and compares each item to the median value, in the left and right arrays, respectively, according to the criteria for(vari = 0; i < arr.length; i++ ){ if(Arr[i] <middlevalue) {Left.push (arr[i]); } Else{Right.push (arr[i]); } } //the left and right arrays are compared recursively, until a recursive termination condition is reached, then the final left, Middlenum, and right are combined and returned returnQuickSort (left). Concat (Middlevalue, QuickSort);}//Testvararr = [3,20,16,12,40,32,1,60,55,30];console.log (QuickSort (arr)); //results: [1, 3, A, (+), (+), +, +, +)
JavaScript enables fast ordering of arrays using recursion