UNPKG

@extra-array/swap-update

Version:
13 lines (12 loc) 270 B
'use strict'; function index(x, i = 0) { return i < 0 ? Math.max(x.length + i, 0) : Math.min(i, x.length); } function swap$(x, i, j) { var i = index(x, i), j = index(x, j); var t = x[i]; x[i] = x[j]; x[j] = t; return x; } module.exports = swap$;