Im trying to create a function that can repeat another function with variable amount of paramemters. However I am only getting the reference to anonymous arrow function rather than the return value of the function (func) I am trying to pass in. I've tried func(). but that seems
const testFunction1 = (x:number,y:number) => {
return {x,y}
}
const testFunction2 = (foo:string, bar:string, baz:string) => {
return {foo, bar, baz}
}
const repeatFunction = (num: number, func: () => unknown) => {
const returnValues: Array<(unknown)> = []
for (let i = 0; i < num; i++) {
returnValues.push(func())
}
return returnValues
}
const result = repeatFunction(5, () => testFunction1(4,5))
console.log(result)
Whats really weird is that when I look into the playground this seems to be working fine. But when I use my editor and debugger I get the following error
Error Uncaught TypeError: func is not a function