093c02d0b9
Fixes a couple of lint errors caught by `npm run lint` in timeline- overview.js and timeline-viewport.js. Also restructures the test- details controller to use appropriate `this.` syntax instead of `$scope.` In addition, eslint and eslint-config-openstack have been updated, and a new .eslintrc.json config file has been created to tweak some specific rules for stackviz. Change-Id: I9e1fe5121621730eb3efda4b99e9fe182f399aee
59 lines
1.1 KiB
JavaScript
59 lines
1.1 KiB
JavaScript
"use strict";
|
|
|
|
var binaryMinIndex = function(min, array, func) {
|
|
|
|
var left = 0;
|
|
var right = array.length - 1;
|
|
|
|
while (left < right) {
|
|
var mid = Math.floor((left + right) / 2);
|
|
|
|
if (min < func(array[mid])) {
|
|
right = mid - 1;
|
|
} else if (min > func(array[mid])) {
|
|
left = mid + 1;
|
|
} else {
|
|
right = mid;
|
|
}
|
|
}
|
|
|
|
if (left >= array.length) {
|
|
return array.length - 1;
|
|
} else if (func(array[left]) <= min) {
|
|
return left;
|
|
} else {
|
|
return left - 1;
|
|
}
|
|
};
|
|
|
|
var binaryMaxIndex = function(max, array, func) {
|
|
|
|
var left = 0;
|
|
var right = array.length - 1;
|
|
|
|
while (left < right) {
|
|
var mid = Math.floor((left + right) / 2);
|
|
|
|
if (max < func(array[mid])) {
|
|
right = mid - 1;
|
|
} else if (max > func(array[mid])) {
|
|
left = mid + 1;
|
|
} else {
|
|
right = mid;
|
|
}
|
|
}
|
|
|
|
if (right < 0) {
|
|
return 0;
|
|
} else if (func(array[right]) <= max) {
|
|
return right + 1; // exclusive index
|
|
} else {
|
|
return right;
|
|
}
|
|
};
|
|
|
|
module.exports = {
|
|
binaryMinIndex: binaryMinIndex,
|
|
binaryMaxIndex: binaryMaxIndex
|
|
};
|