const repeatFn = (n, fn) => {
const results = [];
for (let i = 0; i < n; i++) {
results.push(fn());
}
return results;
};
const result = repeatFn(3, () => Math.random());
console.log(result); // [ 0.50.., 0.25.., 0.08.. ]
Thanks for reading 💙
Follow @codedrops.tech for more.
Instagram ● Twitter ● Facebook
Micro-Learning ● Web Development ● Javascript ● MERN stack
codedrops.tech
Projects
File Ops - A VS Code extension to easily tag/alias files & quick switch between files
Top comments (0)