Skip to content

Conversation

@Sander-Toonen
Copy link

No description provided.

Copilot AI review requested due to automatic review settings January 20, 2026 14:45
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request enhances the add function in the binary arithmetic operators to support additional data types (arrays and objects) and introduces error handling for incompatible type combinations.

Changes:

  • Added explicit handling for number addition to ensure numeric types are added correctly
  • Added array concatenation support using concat()
  • Added object merging support using spread operator
  • Throws an error for incompatible type combinations instead of attempting silent coercion

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +34 to +41
if (
typeof a === 'object' &&
typeof b === 'object' &&
!Array.isArray(a) &&
!Array.isArray(b)
) {
return { ...a, ...b };
}
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic may not handle null values correctly. When both a and b are null, typeof null === 'object' is true, so this condition will be met and return an object spread of null values, which results in an empty object {}. This behavior may be unexpected. Consider adding null checks before the object merge logic.

Copilot uses AI. Check for mistakes.
Comment on lines +28 to +41
// If both values are arrays then we want to concatenate the arrays.
if (Array.isArray(a) && Array.isArray(b)) {
return a.concat(b);
}

// If both values are objects then we want to merge the objects.
if (
typeof a === 'object' &&
typeof b === 'object' &&
!Array.isArray(a) &&
!Array.isArray(b)
) {
return { ...a, ...b };
}
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new behavior for adding arrays (concatenation) and objects (merging) lacks test coverage. The test suite has comprehensive coverage for other operators, but there are no tests verifying that adding two arrays concatenates them or that adding two objects merges them. Consider adding tests to verify this new functionality works as expected.

Copilot uses AI. Check for mistakes.
Comment on lines 48 to 49
// Otherwhise return an error indicating that the values of mixed types cannot be added.
throw new Error(`Cannot add values of different types: ${typeof a} and ${typeof b}`);
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new error throwing behavior lacks test coverage. There are no tests verifying that the function throws an error when attempting to add incompatible types (e.g., number + array, string + object). Consider adding tests to ensure the error is thrown correctly with the expected message.

Copilot uses AI. Check for mistakes.
Sander-Toonen and others added 2 commits January 20, 2026 15:58
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Sander-Toonen
Copy link
Author

@copilot Extend the unit tests for the add function to cover all branches.

Copy link

Copilot AI commented Jan 20, 2026

@Sander-Toonen I've opened a new pull request, #19, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 2 commits January 20, 2026 16:14
* Add comprehensive unit tests for add function covering all branches

Co-authored-by: Sander-Toonen <5106372+Sander-Toonen@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Sander-Toonen Sander-Toonen merged commit 0d88b8e into master Jan 20, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants