I was looking for binary search implementation in Inspector, and found this funny-named function. It actually does more than binary search, so I factored out BS out from it. I added 'binaryIndexOf(value, comparator)' function to Array prototype.
Created attachment 85676 [details] patch
Comment on attachment 85676 [details] patch Looks good except for the test. We don't use initialize_ prefix in the tests.
Created attachment 85679 [details] changed test
Comment on attachment 85679 [details] changed test View in context: https://bugs.webkit.org/attachment.cgi?id=85679&action=review > LayoutTests/inspector/utilities.html:8 > + function BinaryIndexOfTest() start with lowerCase. > LayoutTests/inspector/utilities.html:19 > + function TestArray(array) lowerCase. > LayoutTests/inspector/utilities.html:21 > + function Comparator(a, b) lowerCase > LayoutTests/inspector/utilities.html:49 > + BinaryIndexOfTest(); No need to declare and run - simply inline.
(In reply to comment #4) > (From update of attachment 85679 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=85679&action=review > > > LayoutTests/inspector/utilities.html:8 > > + function BinaryIndexOfTest() > > start with lowerCase. > Done. > > LayoutTests/inspector/utilities.html:19 > > + function TestArray(array) > > lowerCase. > Done. > > LayoutTests/inspector/utilities.html:21 > > + function Comparator(a, b) > > lowerCase > Done. > > LayoutTests/inspector/utilities.html:49 > > + BinaryIndexOfTest(); > > No need to declare and run - simply inline. Done.
Committed manually http://trac.webkit.org/changeset/81029 Web Inspector: Factor out binary search algo from the insertionIndexForObjectInListSortedByFunction function. https://bugs.webkit.org/show_bug.cgi?id=56312 Test: inspector/utilities.html inspector/front-end/utilities.js: inspector/utilities-expected.txt: Added. inspector/utilities.html: Added.