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