function sortInd(arr) {
var isSort, arrInd = [], i, len, temp;
for (i = 0, len = arr.length; i < len; i++) {
arrInd.push(i);
}
do {
isSort = true;
for(i = 0; i < len - 1; i++) {
if (arr[i] > arr[i + 1]) {
isSort = false;
temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
temp = arrInd[i];
arrInd[i] = arrInd[i + 1];
arrInd[i + 1] = temp;
}
}
} while (isSort);
return arrInd;
}
alert(sortInd([3, 1, 2]));