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)