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

155
Views
mostrar la salida en la página html
function shuffleArray(a, n) { let i=0,q=1,k=n while(i<n){ for (let j = k; j > i + q; j--) { let temp = a[j - 1]; a[j - 1] = a[j]; a[j] = temp; } i++; k++; q++; } return a; } a = [2,1,5,3,11,7] shuffleArray(a, a.length / 2); document.getElementById("op").innerHTML = a; <!DOCTYPE html> <html> <head> <title>Shuffle</title> </head> <body> <h1 class="a">Shuffle Array Program</h1> <h2>Input array : [2, 1, 5, 3, 11, 7] </h2> <button onClick=shuffleArray([2, 1, 5, 3, 11, 7],a.length/2)>shuffleArray</button> <h2>Output Array : </h2> <span id="op">Answer : </span> </body> </html>

Estaba probando el método .innerHtml, cuando hago clic en el botón, la respuesta se muestra en el broser, el código JS funciona bien, pero no estoy confundido sobre cómo usarlo con un archivo HTML, ¿alguien puede ayudarme con esta resolución?

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

0

La matriz barajada debe convertirse en una cadena (lo hice con un .join(', ') :

 let a = [2, 1, 5, 3, 11, 7]; const updateOutput = (arr) => { const op = document.getElementById('op') op.innerHTML = arr.join(', ') } const btnShuffle = document.getElementById('shuffle') btnShuffle.addEventListener('click', function() { const shuffled = shuffleArray(a, a.length / 2) updateOutput(shuffled) }) function shuffleArray(a, n) { let i = 0, q = 1, k = n; while (i < n) { for (let j = k; j > i + q; j--) { let temp = a[j - 1]; a[j - 1] = a[j]; a[j] = temp; } i++; k++; q++; } return a; }
 <h1>Shuffle Array Program</h1> <h2>Input array: [2, 1, 5, 3, 11, 7] </h2> <button id="shuffle">shuffleArray</button> <h2>Output Array: </h2>Answer: <span id="op"></span>

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!