UNPKG

jsmodern

Version:

An extension to existing JavaScript, influenced by other great languages such as Rust, Dart, Java, Golang, etc.

20 lines 636 B
export const truncate = { label: 'truncate', fn: function arrayTruncate(len) { const ctx = this; const length = ctx.length; if ('number' !== typeof (len) || len < 0 || len > length) { throw new TypeError(`Expect 'len' to be in the range of 0 and length of array`); } const lenInt = Number(len); if (!lenInt) ctx.length = 0; else if (lenInt < length) { const slice = ctx.slice(0, lenInt); ctx.length = 0; for (const n of slice) ctx.push(n); } }, }; //# sourceMappingURL=truncate.js.map