Build README

This commit is contained in:
Angelos Chalaris
2017-12-14 11:15:49 +02:00
parent f30060a328
commit a528b7f709

View File

@ -57,7 +57,6 @@
* [Promisify](#promisify) * [Promisify](#promisify)
* [Random integer in range](#random-integer-in-range) * [Random integer in range](#random-integer-in-range)
* [Random number in range](#random-number-in-range) * [Random number in range](#random-number-in-range)
* [Randomize order of array](#randomize-order-of-array)
* [Redirect to URL](#redirect-to-url) * [Redirect to URL](#redirect-to-url)
* [Reverse a string](#reverse-a-string) * [Reverse a string](#reverse-a-string)
* [RGB to hexadecimal](#rgb-to-hexadecimal) * [RGB to hexadecimal](#rgb-to-hexadecimal)
@ -597,15 +596,6 @@ const randomInRange = (min, max) => Math.random() * (max - min) + min;
// randomInRange(2,10) -> 6.0211363285087005 // 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 ### Redirect to URL
Use `window.location.href` or `window.location.replace()` to 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. Use `Array.sort()` to reorder elements, using `Math.random()` in the comparator.
```js ```js
const shuffle = arr => { const shuffle = arr => arr.sort(() => Math.random() - 0.5);
let r = arr.map(Math.random); // shuffle([1,2,3]) -> [2,3,1]
return arr.sort((a, b) => r[a] - r[b]);
};
// shuffle([1,2,3]) -> [2, 1, 3]
``` ```
### Similarity between arrays ### Similarity between arrays