Skip to content
This repository was archived by the owner on Dec 13, 2023. It is now read-only.

Conversation

@dothebart
Copy link
Contributor

documentation change for arangodb/arangodb#11042

@dothebart dothebart requested a review from Simran-B February 3, 2020 11:54
- **position** (number): the position of the element to replace. Positions start
at 0. Negative positions are not supported.
at 0. Negative positions are supported, with -1 being the last array element.
If a negative *position* is out of bounds, the array is returned unmodified.
Copy link
Collaborator

Choose a reason for hiding this comment

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

@dothebart Shouldn't the behavior be symmetric with out-of-bounds positive positions? Raise an error if the index points before the first element (or two before it?) unless a padding value is provided leading to [newValue, pad1, pad2, padN, ...oldValues]?

Copy link
Contributor Author

@dothebart dothebart Feb 3, 2020

Choose a reason for hiding this comment

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

make this an if < 0 throw?

 replaceOffset = (static_cast<int64_t>(length) + posParam < 0) ? 0: static_cast<uint64_t>(length + posParam); 

padding below [0] doesn't make sense imho?

Copy link
Collaborator

@Simran-B Simran-B Feb 3, 2020

Choose a reason for hiding this comment

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

It would be pretty uncommon. Since we raise a runtime error when no padding value is provided and the position > length, I think it would make sense to throw also if a negative position points below the first element (or two before 0 to behave analogous to positive positions, where one element after the last is allowed?).

Instead of throwing an error, we could also log a warning in both cases and return the array unaltered. We should definitely not ignore it silently, and I don't have a good feeling about capping the value to a minimum of 0.

@Simran-B Simran-B added this to the 3.7 milestone Feb 4, 2020
@Simran-B Simran-B merged commit c280a9a into master Feb 4, 2020
@Simran-B Simran-B deleted the feature/add-array-replace-nth-function branch February 4, 2020 07:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

2 participants