Skip to content

Instantly share code, notes, and snippets.

@madeleine68
Created September 16, 2021 21:10
Show Gist options
  • Save madeleine68/90856b3a692f1054fc1f27c3afe0b717 to your computer and use it in GitHub Desktop.
Save madeleine68/90856b3a692f1054fc1f27c3afe0b717 to your computer and use it in GitHub Desktop.
const swapper = function(key1, object1, key2, object2) {
console.log('Swap!');
const keyValue1 = object1[key1] //=> 1
const keyValue2 = object2[key2] //=> 5
object1[key1] = keyValue2 // a : 5
object2[key2] = keyValue1 // c : 1
console.log('object1: ', object1);
console.log('object2: ', object2);
}
swapper('a', { a: 1 , b: 2, c: 3 }, 'c', { a: 4, b: 3, c: 5 });
swapper('b', { a: 8 , b: 7, c: 6 }, 'd', { a: 5, b: 1, c: 2, d: 12});
swapper('c', { a: 1 , b: 3, c: 3, d: 7 }, 'c', { a: 4, b: 0, c: 5 });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment