const listaLivros = require('./array');
console.log(quickSort(listaLivros));
function quickSort(list,pivot = list[Math.ceil(list.length/2)-1]){
let result = [];
list.splice(list.indexOf(pivot),1);
list.splice(0,0,pivot);
for(let i=1;i<list.length;i++){
if(list[i].preco<=pivot.preco){
list.splice(0,0,list[i]);
list.splice(i+1,1);
}
}
if(list.length > 2){
if(list.indexOf(pivot)>0){
result.push(...quickSort(list.slice(0,list.indexOf(pivot))));
}
result.push(pivot);
if(list.indexOf(pivot)<list.length-1){
result.push(...quickSort(list.slice(list.indexOf(pivot)+1,list.length)));
}
}else result.push(...list);
return result;
}