| @@ 852-864 (lines=13) @@ | ||
| 849 | * @param array $list |
|
| 850 | * @return int |
|
| 851 | */ |
|
| 852 | function indexOf() { |
|
| 853 | $indexOf = function($item, $list) { |
|
| 854 | if (is_string($list)) { |
|
| 855 | $index = strpos($list, $item); |
|
| 856 | } else { |
|
| 857 | $index = findIndex(equals($item), $list); |
|
| 858 | } |
|
| 859 | return (false === $index || null === $index) |
|
| 860 | ? -1 |
|
| 861 | : $index; |
|
| 862 | }; |
|
| 863 | return apply(curry($indexOf), func_get_args()); |
|
| 864 | } |
|
| 865 | ||
| 866 | /** |
|
| 867 | * Same as `indexOf` but returns the key/position/name of the last item/substring/attribute. |
|
| @@ 882-894 (lines=13) @@ | ||
| 879 | * @param array $list |
|
| 880 | * @return int |
|
| 881 | */ |
|
| 882 | function lastIndexOf() { |
|
| 883 | $lastIndexOf = function($item, $list) { |
|
| 884 | if (is_string($list)) { |
|
| 885 | $index = strrpos($list, $item); |
|
| 886 | } else { |
|
| 887 | $index = findLastIndex(equals($item), $list); |
|
| 888 | } |
|
| 889 | return (false === $index || null === $index) |
|
| 890 | ? -1 |
|
| 891 | : $index; |
|
| 892 | }; |
|
| 893 | return apply(curry($lastIndexOf), func_get_args()); |
|
| 894 | } |
|
| 895 | ||
| 896 | /** |
|
| 897 | * Removes duplicates from a list by keeping the first occurence of each group |
|