function sort(arr) {
var tmp = null;
for(var i = 0; i < arr.length; i++)
for(var j = 0; j < arr.length - 1; j++)
if(arr[j] > arr[j+1]) {
tmp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = tmp;
}
}
function sortStep(arr, i, j, callback) {
if(arr[j] > arr[j + 1]) {
var tmp = arr[j];
var[j] = arr[j + 1];
arr[j + 1] = tmp;
}
if (++j === arr.length - 1) {
i++; j = 0;
}
if (i === arr.length) {
callback();
return;
}
setTimeout(sortStep.bind(this, arr, i, j, callback));
}
function sort(arr, callback) {
if (arr.length < 2) {
callback();
return;
}
sortStep(arr, 0, 0, callback);
}