-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
27 additions
and
37 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
export default function binarySearch(time, timers) { | ||
let start = 0; | ||
let end = timers.length - 2; | ||
let end = timers.length - 5; | ||
let middle; | ||
let l; | ||
|
||
while (start < end) { | ||
// since timers is an array of pairs 'l' will always | ||
// be an integer | ||
l = (end - start) / 2; | ||
l = (end - start) / 5; | ||
|
||
// compensate for the index in case even number | ||
// of pairs inside timers | ||
middle = start + l - (l % 2); | ||
middle = start + l - (l % 5); | ||
|
||
if (time >= timers[middle]) { | ||
start = middle + 2; | ||
start = middle + 5; | ||
} else { | ||
end = middle; | ||
} | ||
} | ||
|
||
return (time >= timers[start]) ? start + 2 : start; | ||
return (time >= timers[start]) ? start + 5 : start; | ||
} |
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