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;
    }
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.