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

168
Views
¿Cómo tomar la entrada del usuario como argumento de función en JavaScript para implementar el algoritmo de ordenación por inserción?

A continuación se muestra la función para ordenar por inserción. Quiero que el usuario proporcione la entrada del formulario html como elementos de matriz en lugar de codificar los elementos de la matriz. He probado varias técnicas pero en vano.

 function insertionSort (inputArr) { let length = inputArr.length; for (let i = 1; i < length; i++) { let key = inputArr[i]; let j = i - 1; while (j >= 0 && inputArr[j] > key) { inputArr[j + 1] = inputArr[j]; j = j - 1; } inputArr[j + 1] = key; } return inputArr; }; let inputArr = [2,4,5,36,2,6,26,8,3,7]; // I want here user input which comes from html form instead of hard-coding elements of array like this insertionSort(inputArr); console.log(inputArr);

// detector de eventos

 function getData() { let userData = document.getElementById('data').value; return userData;

}

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial- scale=1.0"> <title>Insertion Sort In JavaScript</title> </head> <body> <h1>Insertion Sort in JavaScript</h1> <form action="#"> <label for="data">Write Random Numbers</label> <input type="text" name="data" id="data"> &nbsp;&nbsp; <button onclick="getData()">Submit</button> </form> <div id="printData"></div> <script src="insertionsort.js"></script>
about 4 years ago · Juan Pablo Isaza
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!