Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

270
Visualizações
What is the the correct way to call a recursive function while using axios?

Will this allow me to recursively call an API without running indefinitely? *** Do I have to return the function or can I just call it within the function?

const apiUrl = "https://api.website.com/products";
let productArray = [];
let lowPrice = 0;
let highPrice = 100000;

const countProduct = async (lowPrice, highPrice) => {
  const response = await axios.get(apiUrl, {`enter code here`
    params: {
      minPrice: lowPrice,
      maxPrice: highPrice
    }
  });


  let lowerLimit = minPrice;
  let upperLimit = maxPrice;

  while (upperLimit > lowerLimit || response.data.count === 0) {
    if (response.data.count >= 1000) {
        countProduct(lowerLimit, (lowerLimit + upperLimit / 2));  // ***<---  Can I just call the function or do I have to return it 
    } else {
      response.data.products.forEach(product => {
        if (product.price > lowerLimit) { 
          lowerLimit = product.price;
        } 
        productArray.push(product);
      })
      lowerLimit = parseInt(lowerLimit + 0.01);
      upperLimit = parseInt(100000);
    }
  }
};

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda