Skip to content
Subhajit Sahu edited this page Dec 22, 2022 · 14 revisions

Exchange two values.


function swap(x, k, l)
// x: ientries
// k: a key
// l: another key
const ientries = require('extra-ientries');

var x = [["a", 1], ["b", 2], ["c", 3], ["d", 4]];
[...ientries.swap(x, "a", "b")];
// → [ [ "a", 2 ], [ "b", 1 ], [ "c", 3 ], [ "d", 4 ] ]

[...ientries.swap(x, "a", "d")];
// → [ [ "a", 4 ], [ "b", 2 ], [ "c", 3 ], [ "d", 1 ] ]


References

Clone this wiki locally