-
Notifications
You must be signed in to change notification settings - Fork 5
swap$
Subhajit Sahu edited this page May 3, 2023
·
23 revisions
Exchange two values!
function swap$(x, i, j)
// x: an array (updated!)
// i: an index
// j: another index
const xarray = require('extra-array');
var x = [1, 2, 3, 4];
xarray.swap$(x, 0, 1);
// → [ 2, 1, 3, 4 ]
x;
// → [ 2, 1, 3, 4 ]
var x = [1, 2, 3, 4];
xarray.swap$(x, 0, 3);
// → [ 4, 2, 3, 1 ]