JS timer functions are not all that precise. If each different algorithm initializes a different timer, it might be an issue; they might get out of sync. (If you were using recursive setTimeout
s, I know they'd definitely eventually get out of sync if the process took a long time.) Setting just a single timer and running one step for each algorithm inside that timer is probably a more trustworthy approach.
Note that the syntax you'll need will be something like
setInterval(() => {
bubbleSortStep()
insertionSortStep()
quicksortStep()
}, 1000)
(setInterval
accepts a function, not an object)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…