Skip to content

Instantly share code, notes, and snippets.

@McLarenCollege
Created August 11, 2021 11:10
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/12bdda0217983e42e0d52097aa02f065 to your computer and use it in GitHub Desktop.
Save McLarenCollege/12bdda0217983e42e0d52097aa02f065 to your computer and use it in GitHub Desktop.
Find First Occurance of a Character

Given a string, write the code to find the first occurence of a particular character. If the character is found return the index, otherwise return -1

let str = "Today is Sunday";
let char1 = "i";
let char2 = "z";
function findFirstOccurance(str,char){
// write your code here
}
findFirstOccurance(str,char1);// returns 6
findFirstOccurance(str,char2);// returns -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment