Created
April 19, 2012 03:17
-
-
Save SLaks/2418150 to your computer and use it in GitHub Desktop.
Reverse Indentation
This file contains hidden or 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
//One style to revile them all... | |
function binarySearch(arr, ele) | |
{ | |
var beginning = 0, end = arr.length, target; | |
while (true) | |
{ | |
target = ((beginning + end) >> 1); | |
if ((target === end || target === beginning) && arr[target] !== ele) | |
{ | |
return -1; | |
} | |
if (arr[target] > ele) { | |
end = target; | |
} | |
else if (arr[target] < ele) | |
{ | |
beginning = target; | |
} | |
else | |
{ | |
return target; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also great for limiting nesting complexity!