UNPKG

@extra-array/copy-update

Version:

Copies part of array to another.

17 lines (16 loc) 429 B
function index(x, i = 0) { return i < 0 ? Math.max(x.length + i, 0) : Math.min(i, x.length); } function indexRange(x, i = 0, I = x.length) { i = index(x, i); I = Math.max(i, index(x, I)); return [i, I]; } function copy$(x, y, j = 0, i = 0, I = y.length) { var j = index(x, j); var [i, I] = indexRange(y, i, I); for (; i < I; i++, j++) x[j] = y[i]; return x; } export { copy$ as default };