vlocode-project - v1.40.0-beta-4
    Preparing search index...

    Function partition

    • Segregate the elements of the source array into two distinct arrays the first array holding the values for which the predicate returned true and the second array holding the values for which the predicate returned false.

      Type Parameters

      • T

      Parameters

      • array: T[]

        Array to segregate

      • paritioner: (item: T, index: number) => any

        Partion function that puts the item in the right or left bucket depenbding on if it returns a falsish values

      • Optionalpredicate: (item: T, index: number) => any

        Predicate to filter the array

      Returns [T[], T[]]

      A tuple with two arrays the first array holding the values for which the predicate returned true and the second array holding the values for which the predicate returned false.

      // Segregate even and odd numbers
      const [ even, odd ] = partition([ 1, 2, 3, 4, 5 ], i => i % 2 == 0);
      console.log(even); // [ 2, 4 ]
      console.log(odd); // [ 1, 3, 5 ]