Created
June 13, 2017 20:04
-
-
Save remarkablemark/21f407502c7a24b4f86f493e43ced4f3 to your computer and use it in GitHub Desktop.
Invoke a callback `n` number of times using Array, fill, and map (JS).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use strict'; | |
| /** | |
| * Invoke a callback `n` number of times. | |
| * | |
| * @param {Number} n - The times. | |
| * @param {Function} cb - The callback. | |
| */ | |
| function times(n, cb) { | |
| Array(n).fill().map(function(_, i) { | |
| if (typeof cb === 'function') { | |
| cb(i); | |
| } | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment