Build README
This commit is contained in:
17
README.md
17
README.md
@ -57,7 +57,6 @@
|
||||
* [Promisify](#promisify)
|
||||
* [Random integer in range](#random-integer-in-range)
|
||||
* [Random number in range](#random-number-in-range)
|
||||
* [Randomize order of array](#randomize-order-of-array)
|
||||
* [Redirect to URL](#redirect-to-url)
|
||||
* [Reverse a string](#reverse-a-string)
|
||||
* [RGB to hexadecimal](#rgb-to-hexadecimal)
|
||||
@ -597,15 +596,6 @@ const randomInRange = (min, max) => Math.random() * (max - min) + min;
|
||||
// randomInRange(2,10) -> 6.0211363285087005
|
||||
```
|
||||
|
||||
### Randomize order of array
|
||||
|
||||
Use `Array.sort()` to reorder elements, utilizing `Math.random()` to randomize the sorting.
|
||||
|
||||
```js
|
||||
const randomizeOrder = arr => arr.sort((a, b) => Math.random() >= 0.5 ? -1 : 1);
|
||||
// randomizeOrder([1,2,3]) -> [1,3,2]
|
||||
```
|
||||
|
||||
### Redirect to URL
|
||||
|
||||
Use `window.location.href` or `window.location.replace()` to redirect to `url`.
|
||||
@ -667,11 +657,8 @@ const scrollToTop = _ => {
|
||||
Use `Array.sort()` to reorder elements, using `Math.random()` in the comparator.
|
||||
|
||||
```js
|
||||
const shuffle = arr => {
|
||||
let r = arr.map(Math.random);
|
||||
return arr.sort((a, b) => r[a] - r[b]);
|
||||
};
|
||||
// shuffle([1,2,3]) -> [2, 1, 3]
|
||||
const shuffle = arr => arr.sort(() => Math.random() - 0.5);
|
||||
// shuffle([1,2,3]) -> [2,3,1]
|
||||
```
|
||||
|
||||
### Similarity between arrays
|
||||
|
||||
Reference in New Issue
Block a user