-
Notifications
You must be signed in to change notification settings - Fork 0
swap
Subhajit Sahu edited this page Jun 18, 2020
·
15 revisions
Exchanges two values. 🏃 [:vhs:] 📦 🌔 📒
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 ] ]