-
Notifications
You must be signed in to change notification settings - Fork 3
swap
Subhajit Sahu edited this page Dec 8, 2022
·
12 revisions
Exchange two values in an object.
function swap(x, k, l)
// x: an object
// k: a key
// l: another key
const object = require('extra-object');
var x = {a: 1, b: 2, c: 3, d: 4};
object.swap(x, 'a', 'b');
// → { a: 2, b: 1, c: 3, d: 4 }
object.swap(x, 'a', 'd');
// → { a: 4, b: 2, c: 3, d: 1 }