Merge remote-tracking branch 'origin/master'
This commit is contained in:
29
README.md
29
README.md
@ -227,6 +227,7 @@ average(1, 2, 3);
|
|||||||
* [`once`](#once)
|
* [`once`](#once)
|
||||||
* [`runPromisesInSeries`](#runpromisesinseries)
|
* [`runPromisesInSeries`](#runpromisesinseries)
|
||||||
* [`sleep`](#sleep)
|
* [`sleep`](#sleep)
|
||||||
|
* [`times`](#times)
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
@ -3429,6 +3430,34 @@ async function sleepyWork() {
|
|||||||
|
|
||||||
<br>[⬆ Back to top](#table-of-contents)
|
<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
|
## ➗ 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) => {
|
const times = (n, fn, context = undefined) => {
|
||||||
let i = 0;
|
let i = 0;
|
||||||
while (fn.call(context, i) !== false && ++i < n) {}
|
while (fn.call(context, i) !== false && ++i < n) {}
|
||||||
}
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
var output = '';
|
var output = '';
|
||||||
times(5, i => output += i);
|
times(5, i => (output += i));
|
||||||
console.log(output); // 01234
|
console.log(output); // 01234
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user