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

175
Views
Crear una matriz calculada basada en límites

Es hora de elegir el cerebro de la mente de colmena.

Estoy creando un menú desplegable (bueno, 2 de ellos) y necesito que hagan lo siguiente Altura de 4'0 "a 7'0" Peso de 100 lb a 400 lb en incrementos de 5 lb.

¿Cuál sería la forma mejor/más fácil de crear esta matriz sin tener que crear una matriz manualmente?

Sólo tiene que ser tan simple como

 const heights = [ { id: '', name: '' }, ]

Simplemente no sé cómo crearlo mejor en tan pocas líneas de código o creando manualmente la matriz

Lo mismo con la altura en incrementos de 5 libras

EDITAR: PARA QUE la gente sepa POR QUÉ estoy preguntando esto: intente hacer una búsqueda en Google y disfrute de la frustración.

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

0

Para los pesos, puede usar la función Array.fill como se ve en esta respuesta .

 // https://stackoverflow.com/questions/3895478/does-javascript-have-a-method-like-range-to-generate-a-range-within-the-supp const range = (start, stop, step = 1) => Array(Math.ceil((stop - start) / step) + 1).fill(start).map((x, y) => x + y * step) const weights = range(100, 500, 5).map((x, index) => ({ id: index, name: x })) console.log(weights) // or with one line of code const w = Array(Math.ceil((500 - 100) / 5) + 1).fill(100).map((x, index) => ({ name: x + index * 5, id: index })) console.log(w)

Para las alturas, puede usar un algoritmo simple como un bucle while con una condición para el incremento

 const start = { integer: 4, fractionnal: 0 } const end = { integer: 7, fractionnal: 0 } const heights = [] let index = 1 while (start.integer < end.integer || start.fractionnal <= end.fractionnal) { heights.push({ id: index, name: `${start.integer}.${start.fractionnal}` }) if (start.fractionnal < 11) start.fractionnal += 1 else { start.integer += 1 start.fractionnal = 0 } } console.log(heights)

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!