-
Notifications
You must be signed in to change notification settings - Fork 0
swap
Subhajit Sahu edited this page Dec 28, 2022
·
15 revisions
Exchange two values.
function swap(x, k, l)
// x: lists
// k: a key
// l: another key
const xlists = require('extra-lists');
var x = [['a', 'b', 'c', 'd'], [1, 2, 3, 4]];
xlists.swap(x, 'a', 'b').map(c => [...c]);
// → [ [ 'b', 'a', 'c', 'd' ], [ 1, 2, 3, 4 ] ]
xlists.swap(x, 'a', 'd').map(c => [...c]);
// → [ [ 'd', 'b', 'c', 'a' ], [ 1, 2, 3, 4 ] ]