This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
var has = 'hasOwnProperty', slice = Array.prototype.slice; | |
Function.prototype.partial = function () { | |
var method = this, orig = arguments, orig_len = orig.length, key, | |
new_method = function () { | |
var arguments_len = arguments.length, args = [], i = 0, j = 0; | |
if (!arguments_len) return method.apply(this, slice.call(orig)); | |
for (; i < orig_len; i++) | |
args.push(orig[i] === void 0 ? arguments[j++] : orig[i]); | |
return method.apply(this, args.concat(slice.call(arguments, j, arguments_len))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.prototype.search = function (x, l, h, m) { | |
//returns an index >= 0 if arr.search(x) is found | |
//returns a negative index if arr.search(x) is not found | |
//if arr.search(x) < 0, Math.floor(-1 * arr.search(x)) is how many items in arr are smaller than x | |
return arguments.length < 4 ? this.search(x, 0, this.length - 1, Math.floor((this.length - 1) / 2)) | |
: h < l ? l === 0 ? -0.1 : -1 * l | |
: this[m] < x ? this.search(x, m + 1, h, m + 1 + Math.floor((h - (m + 1)) / 2)) | |
: this[m] > x ? this.search(x, l, m - 1, l + Math.floor((m - 1 - l) / 2)) | |
: m; | |
}; |
NewerOlder