Skip to content

Commit 17d7d54

Browse files
committed
Fix index
out of range
1 parent b326a90 commit 17d7d54

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

RaelizeLogic/Sources/RaelizeLogic/UseCase/WordListFileUseCase.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ extension WordListFileUseCaseType {
8181
/// - Returns: Array from the point containing the prefix specified by word to the point specified by candidatesSize
8282
func binarySearch(word: String, candidatesSize: Int, wordList: [String]) -> [String]? {
8383
var left = 0
84-
var right = wordList.endIndex
84+
var right = wordList.count - 1
8585
while left <= right {
8686
let middle = (left + right) / 2
8787

8888
if wordList[middle].lowercased().hasPrefix(word) {
8989
var lastIndex = middle + candidatesSize
90-
lastIndex = wordList.endIndex > lastIndex ? lastIndex : middle // check out of range
90+
lastIndex = wordList.count - 1 > lastIndex ? lastIndex : middle // check out of range
9191
return Array(wordList[middle...lastIndex])
9292
} else if wordList[middle] < word {
9393
left = middle + 1

0 commit comments

Comments
 (0)