Skip to content

Commit 08a9134

Browse files
Complete find function exercise using Python Visualizer for tracing
1 parent 4aaed33 commit 08a9134

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Sprint-3/4-stretch/find.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ console.log(find("code your future", "z"));
2020
// Pay particular attention to the following:
2121

2222
// a) How the index variable updates during the call to find
23+
// index starts at 0.
24+
// The while loop runs as long as index is less than the string length.
25+
// Inside the loop, if the character at index matches the target, the function returns that index.
26+
// If it does not match, index increases by 1 and the loop checks again.
27+
// This continues until the character is found or the end of the string is reached.
2328
// b) What is the if statement used to check
29+
// The if statement checks the character at the current index, and if it matches the target character, it returns the character index (position in the string).
2430
// c) Why is index++ being used?
31+
// index++ increases the index by 1 so the loop can check the next character in the string.
2532
// d) What is the condition index < str.length used for?
33+
// index < str.length ensures the loop runs only while the index is within the string length.
34+
// It stops the loop when the end of the string is reached.

0 commit comments

Comments
 (0)