• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

138
Views
¿Cómo devolver una matriz con el paso de la suma del valor anterior?

¿Cómo devolver una matriz con el paso de la suma del valor anterior?

Tengo un número de entrada que es 1000 y quiero obtener [1000, 2000, 3000 ... 10000]

Estoy tratando de:

 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);
almost 3 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Use Array.from y proporcione el primer argumento como un objeto con propiedad de length que es igual al paso, y el segundo argumento como función de mapeo que simplemente multiplica el índice y el paso:

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

almost 3 years ago · Juan Pablo Isaza Report

0

Prueba esto:

 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 }
almost 3 years ago · Juan Pablo Isaza Report

0

Use un bucle simple y verifique si number * index <= max mientras agrega valores a la nueva matriz:

 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));

almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error