diff --git a/src/filters/array.ts b/src/filters/array.ts index 0a28db9e8..57a7d802d 100644 --- a/src/filters/array.ts +++ b/src/filters/array.ts @@ -8,16 +8,10 @@ import { EmptyDrop } from '../drop' export const join = argumentsToValue(function (this: FilterImpl, v: any[], arg: string) { const array = toArray(v) const sep = isNil(arg) ? ' ' : stringify(arg) - const parts: string[] = [] - let outputSize = array.length > 0 ? sep.length * (array.length - 1) : 0 - for (let i = 0; i < array.length; i++) { - const item = array[i] - const part = isNil(item) ? '' : String(item) - outputSize += part.length - parts.push(part) - } + let outputSize = sep.length * Math.max(array.length - 1, 0) + for (let i = 0; i < array.length; i++) outputSize += String(array[i]).length this.context.memoryLimit.use(outputSize) - return parts.join(sep) + return Array.prototype.join.call(array, sep) }) export const last = argumentsToValue(function (this: FilterImpl, v: any) { return isArrayLike(v) ? readArrayElement(v, -1, this.context.ownPropertyOnly) : ''