-
Notifications
You must be signed in to change notification settings - Fork 0
swap
Subhajit Sahu edited this page Feb 4, 2021
·
14 revisions
Exchanges two values. 🏃 📼 📦 🌔 📒
entries.swap(x, k, l);
// x: entries
// k: a key
// l: another key
const entries = require("extra-entries");
var x = [["a", 1], ["b", 2], ["c", 3], ["d", 4]];
[...entries.swap(x, "a", "b")];
// [ [ "a", 2 ], [ "b", 1 ], [ "c", 3 ], [ "d", 4 ] ]
[...entries.swap(x, "a", "d")];
// [ [ "a", 4 ], [ "b", 2 ], [ "c", 3 ], [ "d", 1 ] ]