Travis build: 1383

This commit is contained in:
30secondsofcode
2018-01-24 11:51:58 +00:00
parent b51bee9022
commit f4888078d4
3 changed files with 39 additions and 3 deletions

View File

@ -227,6 +227,7 @@ average(1, 2, 3);
* [`once`](#once)
* [`runPromisesInSeries`](#runpromisesinseries)
* [`sleep`](#sleep)
* [`times`](#times)
</details>
@ -3429,6 +3430,34 @@ async function sleepyWork() {
<br>[⬆ Back to top](#table-of-contents)
### times
Iterates over a callback `n` times
Use `Function.call()` to call `fn` `n` times or until it returns `false`.
Omit the last argument, `context`, to use an `undefined` object (or the global object in non-strict mode).
```js
const times = (n, fn, context = undefined) => {
let i = 0;
while (fn.call(context, i) !== false && ++i < n) {}
};
```
<details>
<summary>Examples</summary>
```js
var output = '';
times(5, i => (output += i));
console.log(output); // 01234
```
</details>
<br>[⬆ Back to top](#table-of-contents)
---
## ➗ Math

File diff suppressed because one or more lines are too long

View File

@ -9,11 +9,11 @@ Omit the last argument, `context`, to use an `undefined` object (or the global o
const times = (n, fn, context = undefined) => {
let i = 0;
while (fn.call(context, i) !== false && ++i < n) {}
}
};
```
```js
var output = '';
times(5, i => output += i);
times(5, i => (output += i));
console.log(output); // 01234
```