Your task is to create a functionality which can identify whether a number is present in the given array or not. If it is present, then it should return the index of the array of that number, if not then return -1000000.
Inside src/app.js
file -> arrayOfNumbers
and itemToSearch
will be already given to you.
create a global scoped constant NEG_INF
with -1000000 value, and a function createPop
add 2 variables to createPop()
: currIndex, check
- currIndex -> assign
NEG_INF
to this variable - check -> assign
false
to this variable
create a function searchForElement
.
Inside this function -> check whether the given item is present in the array or not, if it is present then assign currIndex to the index at which the item is present, and give check
a true
value, else, if the item is not present -> keep the value of currIndex
as NEG_INF
and the value for check
as false.
In createPop()
, return a function - which uses the updated values of currIndex
and check
(from searchForElement
), in order eturn the following :
- If the element is present in the given array -> then display ->
The item is present and is at index ${currIndex}
- Else, display -->
The item is not present and is at index ${currIndex}
Happy Coding Kalvium ❤️