Skip to content
Subhajit Sahu edited this page Dec 28, 2022 · 15 revisions

Exchange two values.


function swap(x, k, l)
// x: ilists
// k: a key
// l: another key
const xilists = require('extra-ilists');

var x = [['a', 'b', 'c', 'd'], [1, 2, 3, 4]];
xilists.swap(x, 'a', 'b').map(c => [...c]);
// → [ [ 'b', 'a', 'c', 'd' ], [ 1, 2, 3, 4 ] ]

xilists.swap(x, 'a', 'd').map(c => [...c]);
// → [ [ 'd', 'b', 'c', 'a' ], [ 1, 2, 3, 4 ] ]


References

Clone this wiki locally