function bubbleSort(arr){ var arry; var b; var j = 0; if(typeof(arr)=="string"){//如果为字符串数字,则先去逗号转成数组 arry = arr.split(','); }else{ arry = arr; } var len = arry.length; for(var i = 0;i<len;i++) { arry[i] = Number(arry[i]); } for (var i = 0;i<len;i++){ for (var j = 0;j<len-i-1;j++) { if(arry[j]>arry[j+1]){ b = arry[j+1]; arry[j+1] = arry[j]; arry[j] = b; } } } return arry; }