Skip to content

Commit d4fdb43

Browse files
refacoring index_of
1 parent 056ede2 commit d4fdb43

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/IndexOf.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@ function index_of(iterable $haystack, $element, bool $strict = true)
1818
}
1919

2020
foreach ($haystack as $index => $value) {
21-
if ($strict && $element === $value) {
22-
return $index;
23-
}
24-
25-
if (!$strict && $element == $value) {
21+
$matchStrict = $strict && $element === $value;
22+
$matchNonStrict = !$strict && $element == $value;
23+
if ($matchStrict || $matchNonStrict) {
2624
return $index;
2725
}
2826
}

0 commit comments

Comments
 (0)