@extra-array/remove-path-update
Version:
Removes value at path in a nested array.
19 lines (18 loc) • 386 B
JavaScript
function is(v) {
return Array.isArray(v);
}
function last(x, vd) {
return x.length > 0 ? x[x.length - 1] : vd;
}
function getPath(x, p) {
for (var i of p)
x = is(x) ? x[i] : undefined;
return x;
}
function removePath$(x, p) {
var y = getPath(x, p.slice(0, -1));
if (is(y))
y.splice(last(p), 1);
return x;
}
export { removePath$ as default };