bool anyTrue(const double a[], int n) { if (n <= 0) return false; if(somePredicate(a[n-1])) return true; return anyTrue(a, n-1); }
// Return the subscript of the first element in the array for which // the somePredicate function returns true. If there is no such // element, return -1. int firstTrue(const double a[], int n) { if (n <= 0) return -1; int temp = firstTrue(a, n-1); if (somePredicate(a[n-1]) && temp == -1) return n-1; return temp; }
// Return the number of elements in the array for which the // somePredicate function returns true. int countTrue(const double a[], int n) { if (n <= 0) return 0; int temp = countTrue(a+1, n-1); if (somePredicate(a[0])) return 1 + temp; return temp; }
int countTrue(const double a[], int n) { int counter = 0; if(n > 0) { if(somePredicate(a[n-1])) counter++; counter += countTrue(a, n-1); } return counter; }
int firstTrue(const double a[], int n) { int positionHolder = n-1; //im returning the last negative number if(n > 0) { if(somePredicate(a[positionHolder])) { if(n == 1) return positionHolder; else if (firstTrue(a,n-1)== -1) return positionHolder; else return firstTrue(a, n-1); } else return firstTrue(a, n-1); } return -1; }