Skip to content
Subhajit Sahu edited this page Mar 15, 2020 · 23 revisions

Exchanges two values.

array.swap$(x, i, j);
// x: an array (updated)
// i: an index
// j: another index
// --> x
const array = require('extra-array');

var a = [1, 2, 3, 4];
array.swap$(a, 0, 1);
// [2, 1, 3, 4]

a;
// [2, 1, 3, 4]

var a = [1, 2, 3, 4];
array.swap$(a, 0, -1);
// [4, 2, 3, 1]

var a = [1, 2, 3, 4];
array.swap$(a, 0, 0);
// [1, 2, 3, 4]

references

Clone this wiki locally