@extra-array/swap
Version:
Exchanges two values.
49 lines (35 loc) • 1.32 kB
Markdown
Exchanges two values.
[:package:](https://www.npmjs.com/package/@extra-array/swap)
[:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array)
[:running:](https://npm.runkit.com/@extra-array/swap)
[:vhs:](https://asciinema.org/a/332143)
[:moon:](https://www.npmjs.com/package/@extra-array/swap.min)
[:scroll:](https://unpkg.com/@extra-array/swap/)
[:newspaper:](https://nodef.github.io/extra-array/)
[:blue_book:](https://github.com/nodef/extra-array/wiki/)
> Alternatives: [swap], [swap$].
> This is part of package [extra-array].
[extra-array]: https://www.npmjs.com/package/extra-array
<br>
```javascript
array.swap(x, i, j);
// x: an array
// i: an index
// j: another index
```
```javascript
const array = require("extra-array");
var x = [1, 2, 3, 4];
array.swap(x, 0, 1);
// [ 2, 1, 3, 4 ]
array.swap(x, 0, 3);
// [ 4, 2, 3, 1 ]
```
<br>
<br>
## References
- [List-Extra.swapAt: elm](https://package.elm-lang.org/packages/elm-community/list-extra/7.1.0/List-Extra#swapAt)
- [Collections.swap: Java](https://docs.oracle.com/javase/7/docs/api/java/util/Collections.html#swap(java.util.List,%20int,%20int))
- [pure-swap: @alferov](https://www.npmjs.com/package/pure-swap)
[swap]: https://github.com/nodef/extra-array/wiki/swap
[swap$]: https://github.com/nodef/extra-array/wiki/swap$