Skip to content

Commit

Permalink
Address off-by-1 error in FindLastIndex (#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceroypenguin authored Sep 3, 2023
1 parent 23ec78c commit 1797da1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Source/SuperLinq/FindLastIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public static int FindLastIndex<TSource>(this IEnumerable<TSource> source, Func<
var i = 0;
foreach (var element in source)
{
if (i >= index.Value)
if (i > index.Value)
break;

if (predicate(element))
Expand Down
2 changes: 1 addition & 1 deletion Tests/SuperLinq.Test/FindLastIndexTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void FindLastIndexUsesCollectionLengthCorrectly()
array[^6] = 3;
Assert.Equal(
(^6).GetOffset(20),
array.FindLastIndex(i => i == 3, ^5));
array.FindLastIndex(i => i == 3, ^6));
}

[Fact]
Expand Down

0 comments on commit 1797da1

Please sign in to comment.