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

258
Views
Cómo detener una función al hacer clic en el botón en reaccionar JS

Estoy llamando a una función de sort.jsx

<button onClick={() => onBubbleSort()}>Bubble sort</button>

y la definición de la función es:

 BubbleSort() { // console.log(this.state.animationSpeed) let bar = document.getElementsByClassName("arrayElement"); let mySortedArray = bubble.bubblesort(this.state.array, bar, (arr) => { this.setState({ array: arr }); },this.state.animationSpeed); }

Que luego está llamando a una función de clasificación de burbujas en otro archivo bubbleSort.js

 async function bubblesort(array1, element, setState, speed) { let compareSpeed = speed * 1.5; let swapSpeed = speed * 2; let isLessSpeed = speed * 3; let temp; let array = array1; document.getElementById("captions").innerText = "Lets's start sorting with Bubble sort!!!"; await pauseIt(); for (let i = 0; i < array.length - 1; i++) { for (let j = 0; j < array.length - 1 - i; j++) { await compare(element[j], element[j + 1], compareSpeed); if (array[j] > array[j + 1]) { await isLess(element[j], element[j + 1], isLessSpeed); temp = array[j]; array[j] = array[j + 1]; array[j + 1] = temp; await swap(element[j], element[j + 1], swapSpeed); unselect(element[j], element[j + 1],compareSpeed); setState(array); } else { unselect(element[j], element[j + 1],compareSpeed); } } let k = array.length - i - 1; element[k].style.backgroundColor = "green"; if (speed >= 500) await success(i + 1); } element[0].style.backgroundColor = "green"; }

Quiero detener la ejecución de esta función con un clic de botón.

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!