Skip to content

Instantly share code, notes, and snippets.

@remarkablemark
Created June 13, 2017 20:04
Show Gist options
  • Select an option

  • Save remarkablemark/21f407502c7a24b4f86f493e43ced4f3 to your computer and use it in GitHub Desktop.

Select an option

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).
'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