jsmodern
Version:
An extension to existing JavaScript, influenced by other great languages such as Rust, Dart, Java, Golang, etc.
23 lines • 703 B
JavaScript
export const endsWith = {
label: 'endsWith',
fn: function arrayEndsWith(needle) {
const ctx = this;
if (!Array.isArray(needle)) {
throw new TypeError(`Expect 'needle' to be an array`);
}
const ctxLen = ctx.length;
const len = needle.length;
if (!len)
return true;
if (!ctxLen || ctxLen < len)
return false;
const offsetIndex = ctxLen - len;
let matched = 1;
for (let i = 0; i < len; i += 1) {
const val = needle[i];
matched &= Number(val === ctx[i + offsetIndex]);
}
return Boolean(matched);
},
};
//# sourceMappingURL=ends-with.js.map