UNPKG

1.22 kBMarkdownView Raw
1Exchanges two values. [:running:] [:vhs:] [:package:] [:moon:] [:ledger:]
2> Alternatives: [swap], [swap$].<br>
3> This is part of package [extra-object].
4
5[extra-object]: https://www.npmjs.com/package/extra-object
6
7```javascript
8object.swap(x, k, l);
9// x: an object
10// k: a key
11// l: another key
12```
13
14```javascript
15const object = require('extra-object');
16
17var x = {a: 1, b: 2, c: 3, d: 4};
18object.swap(x, 'a', 'b');
19// { a: 2, b: 1, c: 3, d: 4 }
20
21object.swap(x, 'a', 'd');
22// { a: 4, b: 2, c: 3, d: 1 }
23```
24
25### references
26
27- [List-Extra.swapAt: elm](https://package.elm-lang.org/packages/elm-community/list-extra/7.1.0/List-Extra#swapAt)
28- [Collections.swap: Java](https://docs.oracle.com/javase/7/docs/api/java/util/Collections.html#swap(java.util.List,%20int,%20int))
29- [pure-swap: @alferov](https://www.npmjs.com/package/pure-swap)
30
31[:running:]: https://npm.runkit.com/@extra-object/swap
32[:package:]: https://www.npmjs.com/package/@extra-object/swap
33[:moon:]: https://www.npmjs.com/package/@extra-object/swap.min
34[:ledger:]: https://unpkg.com/@extra-object/swap/
35[swap]: https://github.com/nodef/extra-object/wiki/swap
36[swap$]: https://github.com/nodef/extra-object/wiki/swap$
37[:vhs:]: https://asciinema.org/a/338782