-
Notifications
You must be signed in to change notification settings - Fork 0
swap
Subhajit Sahu edited this page Dec 22, 2022
·
14 revisions
Exchange two values.
function 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 ] ]