Skip to content

Instantly share code, notes, and snippets.

@McLarenCollege
Last active March 8, 2022 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save McLarenCollege/dd20534f237fbe423cab6f1b1355d2b6 to your computer and use it in GitHub Desktop.
Save McLarenCollege/dd20534f237fbe423cab6f1b1355d2b6 to your computer and use it in GitHub Desktop.
Index Of Target Name

Given an array of names, write a function that returns the index of the given target name using a for loop. If the name is not present return -1.

Note: There can be duplicate names in the array you have to return first occurence of a given name.

function targetNameIndex(names,target){
  // write your code here
}
let names = ['Vivek','Mark','Pawan','Arnav','Akshat','Zhen','Arnav'];
let targetName = 'Arnav';
console.log(targetNameIndex(names,targetName)); // 3
console.log(targetNameIndex(names,"Abhishek")); // -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment