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

198
Views
¿Cómo obtener una matriz para ignorar los números que no son y establecerla en 1 número por línea?

Estoy creando un programa de número de clasificación de matriz donde el usuario ingresa una matriz de números y al hacer clic en el botón Ordenar clasificará los números en números numéricos. Lo que me pregunto es cómo hacer que mi programa ignore los números que no son números. ¿Y cómo configurarlo en 1 número en cada línea en lugar de ponerlos todos en la misma línea?

 var myarr = []; function addTo() { myarr.push(document.getElementById("userinput").value); console.log(myarr); //to confirm it has been added to the array }; function sortNumbers() { myarr.sort(function(a, b){return a - b}); document.getElementById("userinput").append = myarr; console.log(myarr); }
 <input type="number" id="userinput" /> <input type ="button" onclick="addTo()" value="Add Number" /> <button onclick="sortNumbers()">Sort</button>

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

0

¿Quieres decir esto?

 var myarr = []; function addTo() { let n =document.getElementById("userinput").value; myarr.push(n); document.getElementById("inputA").innerText = myarr.toString(); }; function sortNumbers() { myarr.sort(function(a, b) {return a - b}); ; let sortedB = document.getElementById("sortedB"); document.getElementById("sorted").innerText = myarr.toString(); sortedB.innerHTML = ""; myarr.forEach(n => sortedB.innerHTML += "<br/>" + n); }
 <input type="number" id="userinput" /> <input type ="button" onclick="addTo()" value="Add Number" /> <button onclick="sortNumbers()">Sort</button> <p>Input array: <span id="inputA"></span></p> <p>Sorted on one line: <span id="sorted"></span> <br/> Sorted on different lines: <span id="sortedB"></span> </p>

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!