标签:col mys div nbsp return for floor 索引 获取
var arr = [1, 2, 5, 6, 3, 1, 4]; function mySort(arr) { if (arr.length <= 1) { return arr; } // 获取中间值的索引 var len = Math.floor(arr.length / 2); // 截取中间值 var middle = arr.splice(len, 1); var left = []; var right = []; for (var i = 0; i < arr.length; i++) { if (middle > arr[i]) { left.push(arr[i]) } else { right.push(arr[i]) } } return mySort(left).concat(middle, mySort(right)) } console.log(mySort(arr))//[ 1, 1, 2, 3, 4, 5, 6 ]
标签:col mys div nbsp return for floor 索引 获取
原文地址:http://www.cnblogs.com/samsara-yx/p/7892235.html