Update selectionSort.md
This commit is contained in:
committed by
GitHub
parent
3b4f458782
commit
3e1e383386
@ -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;
|
||||
};
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user