Skip to content
Subhajit Sahu edited this page Feb 4, 2021 · 15 revisions

Exchanges two values. 🏃 📼 📦 🌔 📒


lists.swap(x, k, l);
// x: lists
// k: a key
// l: another key
const lists = require('extra-lists');

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

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


References

Clone this wiki locally