Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
use a function to execute another function (with a variable amount of parameters) Typescript

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

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Most likely you are not passing this function () => testFunction1(4,5) screen

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!