-
-
Save AliceWonderland/0683a94d6fae8f2f93b8a511d82ae16a to your computer and use it in GitHub Desktop.
5.5 My LastIndexOf created by smillaraaq - https://repl.it/HEWJ/1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function myLastIndexOf(arr, searchItem, fromIndex){ | |
| var startIndex=(fromIndex)?fromIndex:arr.length-1; | |
| var output= -1; | |
| for(var i=startIndex;i>=0;i--){ | |
| if(arr[i]===searchItem){ | |
| return output= i; | |
| } | |
| } | |
| return output; | |
| } | |
| console.log(myLastIndexOf([1,2,1], 1)); // => 2 | |
| console.log(myLastIndexOf([1,2,1], 1, 1)); // => 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment