| @@ 975-988 (lines=14) @@ | ||
| 972 | * @param array $list |
|
| 973 | * @return int |
|
| 974 | */ |
|
| 975 | function indexOf() { |
|
| 976 | static $indexOf = false; |
|
| 977 | $indexOf = $indexOf ?: curry(function($item, $list) { |
|
| 978 | if (is_string($list)) { |
|
| 979 | $index = strpos($list, $item); |
|
| 980 | } else { |
|
| 981 | $index = findIndex(equals($item), $list); |
|
| 982 | } |
|
| 983 | return (false === $index || null === $index) |
|
| 984 | ? -1 |
|
| 985 | : $index; |
|
| 986 | }); |
|
| 987 | return _apply($indexOf, func_get_args()); |
|
| 988 | } |
|
| 989 | ||
| 990 | /** |
|
| 991 | * Same as `indexOf` but returns the key/position/name of the last item/substring/attribute. |
|
| @@ 1008-1021 (lines=14) @@ | ||
| 1005 | * @param array $list |
|
| 1006 | * @return int |
|
| 1007 | */ |
|
| 1008 | function lastIndexOf() { |
|
| 1009 | static $lastIndexOf = false; |
|
| 1010 | $lastIndexOf = $lastIndexOf ?: curry(function($item, $list) { |
|
| 1011 | if (is_string($list)) { |
|
| 1012 | $index = strrpos($list, $item); |
|
| 1013 | } else { |
|
| 1014 | $index = findLastIndex(equals($item), $list); |
|
| 1015 | } |
|
| 1016 | return (false === $index || null === $index) |
|
| 1017 | ? -1 |
|
| 1018 | : $index; |
|
| 1019 | }); |
|
| 1020 | return _apply($lastIndexOf, func_get_args()); |
|
| 1021 | } |
|
| 1022 | ||
| 1023 | /** |
|
| 1024 | * Removes duplicates from a list. |
|