Update top JS snippets

This commit is contained in:
Chalarangelo
2021-10-13 20:09:28 +03:00
parent 2b775e3c93
commit 3cd481c0d1
19 changed files with 45 additions and 43 deletions

View File

@ -2,14 +2,14 @@
title: selectionSort
tags: algorithm,array,intermediate
firstSeen: 2020-12-27T22:22:44+02:00
lastUpdated: 2020-12-29T13:04:24+02:00
lastUpdated: 2021-10-13T19:29:39+02:00
---
Sorts an array of numbers, using the selection sort algorithm.
- Use the spread operator (`...`) to clone the original array, `arr`.
- Use a `for` loop to iterate over elements in the array.
- Use `Array.prototype.slice()` and `Array.prototype.reduce()` to find the index of the minimum element in the subarray to the right of the current index and perform a swap, if necessary.
- Use `Array.prototype.slice()` and `Array.prototype.reduce()` to find the index of the minimum element in the subarray to the right of the current index. Perform a swap, if necessary.
```js
const selectionSort = arr => {