Travis build: 1383
This commit is contained in:
29
README.md
29
README.md
@ -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
@ -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
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user