标签:rip script class sea arc == func arch 查找算法
Array.prototype.search = function(value) { var arr = this; function search(arr, value, start, end) { if (start > end) { return -1; } else { var middle = start + end >> 1; if (value > arr[middle]) { return search(arr, value, middle + 1, end) } else if (value < arr[middle]) { return search(arr, value, start, middle - 1); } else if (value === arr[middle]) { return middle; } else { return -1; } } } return search(arr, value, 0, arr.length - 1); }
Array.prototype.search = function(value) { var arr = this; function search(arr, value, start, end) { if (start > end) { return -1; } else { var middle = start + end >> 1; if (value > arr[middle]) { return search(arr, value, middle + 1, end) } else if (value < arr[middle]) { return search(arr, value, start, middle - 1); } else if (value === arr[middle]) { return middle; } else { return -1; } } } return search(arr, value, 0, arr.length - 1); }
标签:rip script class sea arc == func arch 查找算法
原文地址:http://www.cnblogs.com/jiabin-tencent/p/7113386.html