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)