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

126
Views
¿Cómo encuentro el índice medio de una matriz?

Soy nuevo, así que será una pregunta tonta. Recibí una tarea para crear una matriz global, en la que necesitaré importar objetos, ya que se agregan a un campo de entrada en el documento html. Luego, a partir de ahí, necesito actualizar la lista actual en el documento html, pero necesito agregar el elemento central de la matriz a la lista y luego vaciar la matriz. Mi pregunta es, ¿cómo encuentro el índice medio y lo agrego a la matriz? Probé el siguiente código

 const ulList = document.querySelector("ul"); const liElement = document.createElement("li"); liElement.innerHTML = `${globalArray[globalArray.length / 2 - 1].key} ${globalArray[globalArray.length / 2 - 1].manufacturer} ${globalArray[globalArray.length / 2 - 1].model}` ulList.appendChild(liElement); globalArray.splice(globalArray[globalArray.length / 2 - 1], 1);
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

function getArrayMidKey(myArray) { let midKeyIndex = Math.floor(myArray.length / 2) return midKeyIndex; } let snacks = array("Cake", "Soda", "Apples", "Doritos"); midSnack = snacks[getArrayMidKey(snacks)); // midSnack --> "Soda"

Esto le da la clave central de cualquier matriz dada.

Si la matriz tiene 5 elementos, le dará el número de elemento 2, si tiene 6 o 7 elementos, le dará el número de elemento 3 y así sucesivamente.

about 4 years ago · Juan Pablo Isaza Report

0

Math.floor(globalArray.length / 2) globalArray[Math.floor(globalArray.length / 2)]

Prueba esto

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!