@nevware21/ts-utils
    Preparing search index...

    Function arrEvery

    • The arrEvery() method is an iterative method. It calls a provided callbackFn function once for each element in an array, until the callbackFn returns a falsy value. If such an element is found, arrEvery() immediately returns false and stops iterating through the array. Otherwise, if callbackFn returns a truthy value for all elements, every() returns true.

      Type Parameters

      • T

        Identifies the base type of array elements

      • E

        Identifies a more specific instance of the base array type

      Parameters

      • theArray: ArrayLike<T>

        The array or array like object of elements to be searched.

      • callbackFn: ArrPredicateCallbackFn<T, E> | ArrPredicateCallbackFn2<T>

        A function that accepts up to three arguments of type ArrPredicateCallbackFn or ArrPredicateCallbackFn2. The predicate function is called for each element in the thArray until the predicate returns a value which is coercible to the Boolean value false, or until the end of the array.

      • OptionalthisArg: any

        A value to use as this when executing callbackFn. Defaults to the array if not provided.

      Returns theArray is T[]

      true if the callbackFn returns a truthy value for every array elements. Otherwise false.

      0.8.0

      function isBigEnough<T>(element: T, index: number, array: T[]) {
      return element >= 10;
      }

      arrEvery([12, 5, 8, 130, 44], isBigEnough); // false
      arrEvery([12, 54, 18, 130, 44], isBigEnough); // true

      const isSubset = <T>(array1: T[], array2: T[]) => arrEvery(array2, (element) => arrIncludes(array1, element));

      isSubset([1, 2, 3, 4, 5, 6, 7], [5, 7, 6]); // true
      isSubset([1, 2, 3, 4, 5, 6, 7], [5, 8, 7]); // false

      arrEvery([1, , 3], (x) => x !== undefined); // true
      arrEvery([2, , 2], (x) => x === 2); // true

      // Array Like combinations
      isSubset([1, 2, 3, 4, 5, 6, 7], { length: 3, 0: 5, 1: 7, 2: 6}); // true
      isSubset([1, 2, 3, 4, 5, 6, 7], { length: 3, 0: 5, 1: 8, 2: 7}); // false

      isSubset({ length: 7, 0: 1, 1: 2, 2: 3, 3: 4, 4: 5, 5: 6, 6: 7 }, [ 5, 7, 6 ]); // true
      isSubset({ length: 7, 0: 1, 1: 2, 2: 3, 3: 4, 4: 5, 5: 6, 6: 7 }, [5, 8, 7]); // false

      isSubset({ length: 7, 0: 1, 1: 2, 2: 3, 3: 4, 4: 5, 5: 6, 6: 7 }, { length: 3, 0: 5, 1: 7, 2: 6}); // true
      isSubset({ length: 7, 0: 1, 1: 2, 2: 3, 3: 4, 4: 5, 5: 6, 6: 7 }, { length: 3, 0: 5, 1: 8, 2: 7}); // false