@extra-iterable/swap.min

Exchanges two values. :package: :smiley_cat: :running: :vhs: :moon: :scroll: :newspaper: :blue_book:

Usage no npm install needed!

<script type="module">
  import extraIterableSwapMin from 'https://cdn.skypack.dev/@extra-iterable/swap.min';
</script>

README

Exchanges two values. :package: :smiley_cat: :running: :vhs: :moon: :scroll: :newspaper: :blue_book:

This is part of package extra-iterable.

This is browserified, minified version of @extra-iterable/swap.
It is exported as global variable iterable_swap.
CDN: unpkg, jsDelivr.


iterable.swap(x, i, j);
// x: an iterable
// i: an index
// j: another index
const iterable = require("extra-iterable");

var x = [1, 2, 3, 4];
[...iterable.swap(x, 0, 1)];
// [ 2, 1, 3, 4 ]

[...iterable.swap(x, 0, 3)];
// [ 4, 2, 3, 1 ]


References