Created
July 28, 2018 16:13
-
-
Save srishanbhattarai/56fb330bcad5de21c742c68d959339e4 to your computer and use it in GitHub Desktop.
Create an array using a map function
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
/** | |
* Create an array of length 'N' by executing repeaterFn for each item. | |
* This is useful where a method like `getItem()` can return a random item, | |
* and it can be repeated over N times. | |
* | |
* @param {function} repeaterFn | |
* @param {number} N=5 | |
* @returns {Array} | |
*/ | |
const repeat = (repeaterFn, N = 5) => Array(...Array(N)).map(repeaterFn) | |
export default repeat |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment