Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

173
Vistas
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 Respuestas
Responde la pregunta

0

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

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda