Skip to content

Instantly share code, notes, and snippets.

@rcjasub
Created June 17, 2025 19:10
Show Gist options
  • Save rcjasub/21866b3e343fe26fb5e5ff3fd080c0be to your computer and use it in GitHub Desktop.
Save rcjasub/21866b3e343fe26fb5e5ff3fd080c0be to your computer and use it in GitHub Desktop.
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