quxt
Version:
Lodash but OVERPOWERED!
23 lines (19 loc) • 429 B
JavaScript
function quickSort(items) {
const length = items.length
if (length <= 1) {
return items
}
const PIVOT = items[0]
const GREATER = []
const LESSER = []
for (let i = 1; i < length; i++) {
if (items[i] > PIVOT) {
GREATER.push(items[i])
} else {
LESSER.push(items[i])
}
}
const sorted = [...quickSort(LESSER), PIVOT, ...quickSort(GREATER)]
return sorted
}
module.exports = quickSort