Skip to content

Docs: isStrictEqual and areArraysEqual JSDoc incorrectly describes array comparison as order-independent #5162

@Zelys-DFKH

Description

@Zelys-DFKH

Summary

Changes

Please provide a summary of what's being changed

What were you searching in the docs?
I was reading the API reference for isStrictEqual in the commons package to understand how it compares arrays.

Is this related to an existing documentation section?
https://github.com/aws-powertools/powertools-lambda-typescript/blob/main/packages/commons/src/typeUtils.ts

How can we improve?
The JSDoc for isStrictEqual and areArraysEqual says array comparison is "regardless of order", but the implementation is order-dependent. It compares elements at the same index: left.every((value, i) => isStrictEqual(value, right[i])).

The existing unit test confirms this: isStrictEqual([1, 2, 3], [1, 3, 2]) is expected to return false.

Two things in the JSDoc are wrong:

  1. areArraysEqual says "This function compares each element in the arrays, regardless of order." It should say something like "at the same position".
  2. isStrictEqual has the same issue. The code example shows isStrictEqual([1, 2, 3], [3, 2, 1]) // true, but the actual return value is false.

Suggestion:

  • Change "regardless of order" to "at the same position" in both JSDoc blocks.
  • Update the isStrictEqual example: either change [3, 2, 1] to [1, 2, 3], or change the comment from // true to // false.

Acknowledgment

  • I understand the final update might be different from my proposed suggestion, or refused.

Metadata

Metadata

Assignees

Labels

completedThis item is complete and has been merged/shipped

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions