ts-data-forge
    Preparing search index...
    • Checks if two IMapMapped instances are structurally equal.

      Two IMapMapped instances are considered equal if they have the same size and contain exactly the same key-value pairs. The comparison is performed on the underlying mapped keys and values, so the transformation functions themselves don't need to be identical. Values are compared using JavaScript's === operator.

      Performance: O(n) where n is the size of the smaller map.

      Type Parameters

      • K

        The type of the custom keys.

      • V

        The type of the values.

      • KM extends Primitive

        The type of the mapped primitive keys.

      Parameters

      Returns boolean

      true if the maps contain exactly the same key-value pairs, false otherwise.

      type Point = Readonly<{ x: number; y: number }>;

      const toKey = (p: Point) => JSON.stringify(p);

      // eslint-disable-next-line total-functions/no-unsafe-type-assertion
      const fromKey = (key: string) => JSON.parse(key) as Point;

      const first = IMapMapped.create<Point, string, string>(
      [
      [{ x: 0, y: 0 }, 'origin'],
      [{ x: 1, y: 0 }, 'right'],
      ],
      toKey,
      fromKey,
      );

      const second = IMapMapped.create<Point, string, string>(
      [
      [{ x: 1, y: 0 }, 'right'],
      [{ x: 0, y: 0 }, 'origin'],
      ],
      toKey,
      fromKey,
      );

      const third = IMapMapped.create<Point, string, string>(
      [[{ x: 0, y: 0 }, 'different']],
      toKey,
      fromKey,
      );

      assert.isTrue(IMapMapped.equal(first, second));

      assert.isFalse(IMapMapped.equal(first, third));