Skip to content

Commit

Permalink
fix: make swap work when swapped items are arrays (ramda#3394)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhangjun authored Jul 28, 2023
1 parent 6dd4ac9 commit 165d2ae
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions source/swap.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ var swapList = function(indexA, indexB, list) {

result = []
.concat(result.slice(0, positiveMin))
.concat(result[positiveMax])
.concat([result[positiveMax]])
.concat(result.slice(positiveMin + 1, positiveMax))
.concat(result[positiveMin])
.concat([result[positiveMin]])
.concat(result.slice(positiveMax + 1, length));

return result;
Expand Down
4 changes: 4 additions & 0 deletions test/swap.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ describe('swap', function() {
eq(R.swap(0, 1, list), R.swap(1, 0, list));
});

it('works with lists of arrays', function() {
eq(R.swap(0, -1, [['a', 'A'], ['b', 'B']]), [['b', 'B'], ['a', 'A']]);
});

it('swaps property values from one property to another', function() {
eq(R.swap('a', 'b', {a: 1, b: 2}), {a: 2, b: 1});
eq(R.swap('b', 'a', {a: 1, b: 2}), {a: 2, b: 1});
Expand Down

0 comments on commit 165d2ae

Please sign in to comment.