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

232
Visualizações
How to return an array with the step of the sum of the previous value?

How to return an array with the step of the sum of the previous value?

I have an input number that is 1000 I want to get [1000, 2000, 3000 ... 10000]

I'm trying to:

  const range = (i: number, o: number) => {
    const arr = [0, 1, 2, 3, 4].reduce(
      (accumulator: any, currentValue: any, index: any, array: any) => {
        console.log((array[index] = accumulator + currentValue));
        return 1;
      },
      10000
    );
  };

  range(1000, 10000);
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Use Array.from and provide the first argument as an object with length property that is equal to the step, and second argument as mapping function that simply multiply the index and step:

const range = (start,end) => 
    Array.from( {length: end/start} ,(_,i) => (i+1) * start )
      
console.log(range(1000,10000))

about 4 years ago · Juan Pablo Isaza Relatório

0

Try this:

function range(start, end) {
    var arr = []; // Start with an empty array

    /* Start a counter at the start value, and increment it
     * by the start value while it is less than or equal to
     * the end value. Push this value into arr each time
     */
    for (let i = start; i <= end; i += start) {
        arr.push(i);
    }

    return arr; // Return the array
}
about 4 years ago · Juan Pablo Isaza Relatório

0

Use simple loop and check if number * index <= max while adding values to new array:

  const range = (number, max) => {
    let index = 1;
    let newArray = [];

    do {
      newArray.push(number * index);
      index++;
    } while (number * index <= max);
    
    return newArray;
  };

  console.log(range(1000, 10000));

  console.log(range(10000, 10000));

about 4 years ago · Juan Pablo Isaza Relatório
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