Skip to content

Commit

Permalink
refactor: prevent array.nextItem and array.previousItem to return null
Browse files Browse the repository at this point in the history
  • Loading branch information
jorenrui committed Mar 24, 2024
1 parent 2d8367f commit 7114a15
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/helpers/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class MiniArray extends Array {
} else {
const flatArray = this.deepFlat()
const nextIndex = flatArray.indexOf(item) + 1
if (nextIndex === -1) return null
if (nextIndex === -1) return flatArray.first
return nextIndex >= flatArray.length ? flatArray.first : flatArray.at(nextIndex)
}
}
Expand All @@ -147,7 +147,7 @@ export class MiniArray extends Array {
} else {
const flatArray = this.deepFlat()
const previousIndex = flatArray.indexOf(item) - 1
if (previousIndex === -1) return null
if (previousIndex === -1) return flatArray.last
return previousIndex < 0 ? flatArray.last : flatArray.at(previousIndex)
}
}
Expand Down

0 comments on commit 7114a15

Please sign in to comment.