Update selectionSort.md

This commit is contained in:
Isabelle Viktoria Maciohsek
2020-12-29 13:04:24 +02:00
committed by GitHub
parent 3b4f458782
commit 3e1e383386

View File

@ -12,14 +12,12 @@ Sorts an array of numbers, using the selection sort algorithm.
```js
const selectionSort = arr => {
const a = [...arr];
for (let i = 0; i < a.length; i++) {
const min = a
.slice(i + 1)
.reduce((acc, val, j) => (val < a[acc] ? j + i + 1 : acc), i);
if (min !== i) [a[i], a[min]] = [a[min], a[i]];
}
return a;
};
```