-
Notifications
You must be signed in to change notification settings - Fork 1
swap
Subhajit Sahu edited this page May 9, 2020
·
19 revisions
Exchanges two values. [:running:] [:vhs:] [:package:] [:moon:]
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]
[...iterable.swap(x, 0, 0)];
// [1, 2, 3, 4]
- Collections.swap(): Java
- pure-swap: @alferov
- List-Extra.swapAt(): elm [:running:]: https://npm.runkit.com/@extra-iterable/swap [:vhs:]: https://asciinema.org/a/EU8HavAAkEwmkH9Eteb8Sj9Bx [:package:]: https://www.npmjs.com/package/@extra-iterable/swap [:moon:]: https://www.npmjs.com/package/@extra-iterable/swap.min