File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed
Sprint-3/revise/investigate Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change 11function find ( str , char ) {
2- //this var will store once find the index === to equal.
2+ // Initialize a variable to store the index of the matched character
33 let index = 0 ;
44
55 // The while loop iterates through each character in the string
6- //while loop will map the string and find if there is any match character in the string.
6+ // It checks if the current character matches the input character
77 while ( index < str . length ) {
88 if ( str [ index ] === char ) {
9- // If the character at the current index matches the input char, return the index
9+ // If a match is found, return the index of the matching character
1010 return index ;
1111 }
12- //update the value of index and continue until index is less than the str.length.
12+ // Increment the index to check the next character
1313 index ++ ;
1414 }
15- // If the loop completes and no match is found, return -1
15+ // If no match is found after the loop finishes , return -1
1616 return - 1 ;
1717}
1818
You can’t perform that action at this time.
0 commit comments