Skip to content

Commit 78bf61f

Browse files
committed
fix: Array#space handling for ends when length = 1
1 parent 55af359 commit 78bf61f

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

src/globals/prototypes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ Object.defineProperties(Array.prototype, {
250250
writable: false,
251251
configurable: false,
252252
value: function <T, S>(this: T[], spacer: S, ends?: boolean): (T | S)[] {
253-
if (this.length === 0 || this.length === 1) return this;
253+
if (this.length === 0) return [];
254+
if (this.length === 1) return ends ? [spacer, this[0], spacer] : [this[0]];
254255
return this.slice(1)
255256
.reduce<(T | S)[]>(
256257
(acc, term) => {

0 commit comments

Comments
 (0)