i have made an quick sort algorithm, but it returns a string instead of an wanted array.
const quickSort = (arr) => {
if (arr.length < 2) {
return arr;
} else {
let pivot = arr[0]
let less = arr.slice(1).filter(i => i <= pivot)
let grater = arr.slice(1).filter(i => i > pivot)
return quickSort(less) + [pivot] + quickSort(grater);
}
}
console.log(quickSort([1, 5, 93, 2]));
I can’t figure out why, my guess it that is has some thing to do with the line:
return quickSort(less) + [pivot] + quickSort(grater);