Update top JS snippets
This commit is contained in:
@ -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 => {
|
||||
|
||||
Reference in New Issue
Block a user