Skip to content
Subhajit Sahu edited this page Jun 18, 2020 · 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 = [[], []];
var x = [['a', 1], ['b', 2], ['c', 3], ['d', 4]];
[...lists.swap(x, 'a', 'b')];
// [ [ 'a', 2 ], [ 'b', 1 ], [ 'c', 3 ], [ 'd', 4 ] ]

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

references

Clone this wiki locally