Skip to content

Instantly share code, notes, and snippets.

@yuriy-o
Created September 27, 2022 12:57
Show Gist options
  • Save yuriy-o/39b60c25cf5a114ea36c4ba0a017127c to your computer and use it in GitHub Desktop.
Save yuriy-o/39b60c25cf5a114ea36c4ba0a017127c to your computer and use it in GitHub Desktop.
QuickSort сортування
// ---- quicksort ----
// function quicksort(numbers) {
// if (numbers.length < 2) return numbers;
// const pivot = numbers[0];
// const left = [];
// const right = [];
// for (let i = 1; i < numbers.length; i++) {
// numbers[i] < pivot ? left.push(numbers[i]) : right.push(numbers[i]);
// }
// return quicksort(left).concat(pivot, quicksort(right));
// }
// console.log(quicksort([5, 2, 4, 8, 1, 7, 6, 3, 9]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment