jty
    Preparing search index...

    Function isSameArr

    • Checks if two arrays are the same. Two arrays are considered the same if they have the same length and their elements are strictly equal at each index. This function acts as a type guard, narrowing the type of b to be the same as a if it returns true.

      Type Parameters

      • T

      Parameters

      • x: unknown

        The first value to compare.

      • ref: T[]

        The reference array.

      Returns x is T[]

      true if the arrays are the same, false otherwise.

      const refArr = [1, 2, 3];
      const unknownArr: unknown = [1, 2, 3];
      isSameArr([1, 2, 3], [1, 2, 3]) => true
      isSameArr([1, 2, 3], [1, 2, 3, 4]) => false
      isSameArr([1, 2, 3, 4], [1, 2, 3]) => false
      isSameArr([1, 2, 3], []) => true
      isSameArr([], [1, 2, 3]) => false
      isSameArr({}, [1, 2, 3]) => false
      isSameArr([1, 2, 3], [3, 2, 1]) => false

      if ref is not an array.