Skip to content
Subhajit Sahu edited this page Jun 11, 2020 · 12 revisions

Exchanges two values. 🏃 📼 📦 🌔 📒

Alternatives: swap, swap$.

object.swap$(x, k, l);
// x: an object (updated)
// k: a key
// l: another key
// --> x
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 }

x;
// { a: 2, b: 1, c: 3, d: 4 }

var x = {a: 1, b: 2, c: 3, d: 4};
object.swap$(x, 'a', 'd');
// { a: 4, b: 2, c: 3, d: 1 }

references

Clone this wiki locally