Created
June 17, 2025 19:10
-
-
Save rcjasub/21866b3e343fe26fb5e5ff3fd080c0be to your computer and use it in GitHub Desktop.
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 myUnshift(arr, target) | |
{ | |
if(arr.length !== 0) | |
{ | |
for(let i = arr.length - 1; i >= 0; i--) | |
{ | |
if (arr[i] === target) { | |
return i; | |
} | |
} | |
} | |
return -1; | |
} | |
const animals = ['cat', 'dog', 'bird', 'dog', 'fish']; | |
console.log(myUnshift(animals, 'dog')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment