Build README

This commit is contained in:
Angelos Chalaris
2017-12-13 12:13:34 +02:00
parent 7843d2552f
commit c0ed8da9fd
2 changed files with 18 additions and 2 deletions

View File

@ -12,6 +12,7 @@
* [Average of array of numbers](#average-of-array-of-numbers) * [Average of array of numbers](#average-of-array-of-numbers)
* [Capitalize first letter of every word](#capitalize-first-letter-of-every-word) * [Capitalize first letter of every word](#capitalize-first-letter-of-every-word)
* [Capitalize first letter](#capitalize-first-letter) * [Capitalize first letter](#capitalize-first-letter)
* [Chain asynchronous functions](#chain-asynchronous-functions)
* [Check for palindrome](#check-for-palindrome) * [Check for palindrome](#check-for-palindrome)
* [Chunk array](#chunk-array) * [Chunk array](#chunk-array)
* [Count occurrences of a value in array](#count-occurrences-of-a-value-in-array) * [Count occurrences of a value in array](#count-occurrences-of-a-value-in-array)
@ -110,6 +111,21 @@ const capitalize = (str, lowerRest = false) =>
// capitalize('myName', true) -> 'Myname' // capitalize('myName', true) -> 'Myname'
``` ```
### Chain asynchronous functions
Loop through an array of functions containing asynchronous events, calling `next` when each asynchronous event has completed.
```js
const chainAsync = fns => { let curr = 0; const next = () => fns[curr++](next); next(); }
/*
chainAsync([
next => { console.log('0 seconds'); setTimeout(next, 1000); },
next => { console.log('1 second'); setTimeout(next, 1000); },
next => { console.log('2 seconds'); }
])
*/
```
### Check for palindrome ### Check for palindrome
Convert string `toLowerCase()` and use `replace()` to remove non-alphanumeric characters from it. Convert string `toLowerCase()` and use `replace()` to remove non-alphanumeric characters from it.

View File

@ -4,11 +4,11 @@ Loop through an array of functions containing asynchronous events, calling `next
```js ```js
const chainAsync = fns => { let curr = 0; const next = () => fns[curr++](next); next(); } const chainAsync = fns => { let curr = 0; const next = () => fns[curr++](next); next(); }
/* /*
chainAsync([ chainAsync([
next => { console.log('0 seconds'); setTimeout(next, 1000); }, next => { console.log('0 seconds'); setTimeout(next, 1000); },
next => { console.log('1 second'); setTimeout(next, 1000); }, next => { console.log('1 second'); setTimeout(next, 1000); },
next => { console.log('2 seconds');} next => { console.log('2 seconds'); }
]) ])
*/ */
``` ```