Repeat Function Invocation
Invokes a function a specified number of times.
- function
- repeat
Install
npx shadcn@latest add https://quicksnip.dev/r/repeat-function-invocation.jsonThis snippet is not verified yet. Review it before use, or help verify it.
Code
const times = (func, n) => {
Array.from(Array(n)).forEach(() => {
func();
});
};Usage
const randomFunction = () => console.log('Function called!');
times(randomFunction, 3); // Logs 'Function called!' three times