-1
I need to write a function that takes two parameters, the first being an array of numbers and the second being any number.
The function needs to check whether the second parameter (which can be any number) is contained in the array (first parameter)
I thought about the following javascript code:
function contem(array,y){
var array = [];
### tentei fazer o programa ler o primeiro parâmetro como um array(ñ funcionou)
for(i = 0; i < array.lenght; i++){
if (i == y){
return true
}
else {
return false
}
}
}
explanation of the code / doubts:
How do for q the function understands that the first parameter is an array?
I thought to declare a variable and say that it is equal to an empty array, but it is not working.
- My idea is to create a loop for q scans the array and if y (second parameter) returns true, otherwise (Else) returns false.
BS.: If you have something you can read too eh valid, this exercise is part of an online challenge, I am about 10 hours trying to do and nda ....
The correct is
if(array[i] == y)
.– user142154
@v.Saints Thanks, corrected.
– Renan Gomes