blob: c99e44f6451258fb55d40b5a101cb8cc9e36311d [file] [log] [blame]
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
/**
* Takes a sorted array and a function p. The array is sorted in such a way that all elements where p(x) is false
* are located before all elements where p(x) is true.
* @returns the least x for which p(x) is true or array.length if no element fullfills the given function.
*/
export function findFirst(array, p) {
var low = 0, high = array.length;
if (high === 0) {
return 0; // no children
}
while (low < high) {
var mid = Math.floor((low + high) / 2);
if (p(array[mid])) {
high = mid;
}
else {
low = mid + 1;
}
}
return low;
}
export function includes(array, item) {
return array.indexOf(item) !== -1;
}
export function union() {
var arrays = [];
for (var _i = 0; _i < arguments.length; _i++) {
arrays[_i] = arguments[_i];
}
var result = [];
for (var _a = 0, arrays_1 = arrays; _a < arrays_1.length; _a++) {
var array = arrays_1[_a];
for (var _b = 0, array_1 = array; _b < array_1.length; _b++) {
var item = array_1[_b];
if (!includes(result, item)) {
result.push(item);
}
}
}
return result;
}