Skip to content

Instantly share code, notes, and snippets.

@SLaks
Created April 19, 2012 03:17
Show Gist options
  • Save SLaks/2418150 to your computer and use it in GitHub Desktop.
Save SLaks/2418150 to your computer and use it in GitHub Desktop.
Reverse Indentation
//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;
}
}
}
@SLaks
Copy link
Author

SLaks commented Apr 19, 2012

Also great for limiting nesting complexity!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment