I have successfully implemented a bubble sort algorithm and now I am facing an issue with re-rendering the UI after each iteration. Currently, when I run the function runBubbleSort()
, the algorithm terminates instantly and displays the correct result. Is there a way to introduce a timer of 50ms before executing the next loop iteration?
runBubbleSort: function(event) {
for (var j = 1; j < this.elements.length; j++) {
for (var i = 0; i < this.elements.length - j; i++) {
// code to set timer goes here
if (this.elements[i] > this.elements[i + 1]) {
var tmp = this.elements[i];
this.$set(this.elements, i, this.elements[i + 1]);
this.$set(this.elements, i + 1, tmp);
}
}
}
}