UNPKG

@extra-array/swap-update

Version:
54 lines (39 loc) 1.41 kB
Exchanges two values. [:package:](https://www.npmjs.com/package/@extra-array/swap-update) [:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array) [:running:](https://npm.runkit.com/@extra-array/swap-update) [:vhs:](https://asciinema.org/a/332142) [:moon:](https://www.npmjs.com/package/@extra-array/swap-update.min) [:scroll:](https://unpkg.com/@extra-array/swap-update/) [: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 (updated) // i: an index // j: another index // → x ``` ```javascript const array = require("extra-array"); var x = [1, 2, 3, 4]; array.swap$(x, 0, 1); // [ 2, 1, 3, 4 ] x; // [ 2, 1, 3, 4 ] var x = [1, 2, 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$