I implemented a project for sorting algorithms visualization. It is a simple static website made using HTML, CSS and JavaScript. It uses DOM manipulation to visualize how an algorithm looks like in working. There are separate buttons for each algorithm and an event listener attached to each of them, which executes respective sorting algorithms.
Now, if I have to reset the page when any function is in execution, performing the sorting visualization, I have to simply refresh the page. But instead, I want to add a reset / abort button, which do the same thing as the page refresh do, mainly stopping the function in execution performing sorting visualization. There are recursive functions for Merge and Quick Sort as well.
I tried googling for the same and found this article, but it didn't solved my problem.
I've also found about setTimeout(fun, ms) & clearTimeout(id), but did not understood how it would work in my case with recursive functions.
So, I want to ask, how to implement such a button which has the same functionality like a page refresh button do.