I have the following goal: Write a JavaScript function called filter
that receives an array of numbers as a parameter and returns a new array with numbers greater than 10.
filter([3, 12, 45, 7]); // retorna [12, 45]
filter([3, 5]); // retorna []
How can I do to return a new array with these numbers greater than 10?
My code is like this:
function filter (array){
var cont = 0;
for (let i=0; i< array.length; i++){
if(array[i] >= 10 ){
cont = cont++;
}
}
return [cont];
}
let resultado = filter([3, 12, 45, 7]);
console.log(resultado);