You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Swap two elements in an array
@since version
@category Array
@param {array} The array where the elements would be swapped.
@param {indexA} The index of the first element.
@param {indexB} The index of the second element.
2) Pseudo Code
function swapArrayByIndex(array, indexA, indexB){
// Creating new array
// Swapping the new array elements of indexA and indexB
// Return new array
}
I would be interested in seeing a PR for a swap function. It seems useful. It seems to make sense for it to work on arrays with indices and also on objects with keys.
But I don't see this replacing move. swap would adjust the values at two indices/keys. move on arrays, adjusts the values at all indices between the source and target.
I have indeed had use cases for swap and would like to see it added, but I don't know why you want to replace move with it. move is just as fundamental and useful and its a completely different function.
#3065
1) Design
2) Pseudo Code
3) Output
Basic
Out of index
Misc
4) Test
Identity
Follows identity when indexA and indexB are identical
Commutative
Follows commutative when indexA and indexB are interchanged
Associative
Doesn't Follow associative
5) Quality
Data Immutability
6) Ideas
To create an object swap function which will swap the values of given object.
Inform us if you also want us to implement these ideas.
The text was updated successfully, but these errors were encountered: