Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* binary search of an array
- Performs a binary search on the host array. This method can either be
- injected into Array.prototype or called with a specified scope like this:
- binaryIndexOf.call(someArray, searchElement);
- http://jsperf.com/binaryindexof-and-indexof/3 */
- */
- function binaryIndexOf(e){for(var b=0,c=this.length-1,a,d;b<=c;)if(a=(b+c)/2|0,d=this[a],d<e)b=a+1;else if(d>e)c=a-1;else return a;return-1}
- Array.prototype.binaryIndexOf=binaryIndexOf;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement