# All files / utils unzip.ts

94.74% Statements 18/19
75% Branches 9/12
100% Functions 5/5
94.44% Lines 17/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    341x

    1x
    7x

    1x
    21x

    1x
    2x

    2x
    2x
    7x
    7x
    7x

    2x
    2x
    2x
    6x

    2x

     import {isLength} from './isLength'

    const isArrayLikeObject = value => {
      return (
        typeof value === 'object' &&
        value !== null &&
        typeof value !== 'function' &&
        isLength(value.length)
      )
    }

    const baseProperty = key => {
      return object => (object == null ? undefined : object[key])
    }

    export const unzip = (array: Array<any>) => {
      Iif (!(Array.isArray(array) && array.length)) {
        return []
      }
      let length = 0
      array = array.filter(group => {
        Eif (isArrayLikeObject(group)) {
          length = Math.max(group.length, length)
          return true
        }
      })
      let index = -1
      const result = new Array(length)
      while (++index < length) {
        result[index] = array.map(baseProperty(index))
      }
      return result
    }