Search⌘ K
AI Features

Challenge 2: Search the First Occurrence of a Number

Explore how to use recursion to search for the first occurrence of a number in an array starting from a given index. This lesson helps you understand recursive problem-solving techniques by implementing a function that returns the index where the target number appears first or -1 if it is absent.

Problem Statement

Implement a function that takes an array arr, a testVariable containing the number to search and currentIndex containing the starting index as parameters and outputs the index of the first occurrence of testVariable in arr. If testVariable is not found in ...