Build README

This commit is contained in:
Angelos Chalaris
2017-12-14 10:35:58 +02:00
parent b07804069a
commit b7f716ef42
2 changed files with 23 additions and 5 deletions

View File

@ -64,6 +64,7 @@
* [Scroll to top](#scroll-to-top)
* [Shuffle array values](#shuffle-array-values)
* [Similarity between arrays](#similarity-between-arrays)
* [Sleep](#sleep)
* [Sort characters in string (alphabetical)](#sort-characters-in-string-alphabetical)
* [Sum of array of numbers](#sum-of-array-of-numbers)
* [Swap values of two variables](#swap-values-of-two-variables)
@ -667,6 +668,21 @@ const similarity = (arr, values) => arr.filter(v => values.includes(v));
// similarity([1,2,3], [1,2,4]) -> [1,2]
```
### Sleep
Delay executing part of an `async` function, by putting it to sleep, returning a `Promise`.
```js
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
/*
async function sleepyWork() {
console.log('I\'m going to sleep for 1 second.');
await sleep(1000);
console.log('I woke up after 1 second.');
}
*/
```
### Sort characters in string (alphabetical)
Split the string using `split('')`, `Array.sort()` utilizing `localeCompare()`, recombine using `join('')`.

View File

@ -4,9 +4,11 @@ Delay executing part of an `async` function, by putting it to sleep, returning a
```js
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
// async function sleepyWork() {
// console.log('I\'m going to sleep for 1 second.');
// await sleep(1000);
// console.log('I woke up after 1 second.');
// }
/*
async function sleepyWork() {
console.log('I\'m going to sleep for 1 second.');
await sleep(1000);
console.log('I woke up after 1 second.');
}
*/
```