Hello I'm running some tests to see if the output of both is true. The thing is that given these conditions:
var callback = function (num) {
return num % 2 === 0
}
console.log($$$.any([1, 3, 4], callback) === true)
console.log($$$.any([1, 11, 111], callback) === false)
I have to create a function that gives as a result in both cases true. I did it with a for loop but I can't get the same result with a forEach, why is that?:
// My for loop function:
$$$ = {
any: function (arr, callback) {
for (var i = 0, l = arr.length; i < l; i ++) {
if (callback(arr[i])) {
return true;
}
}
return false;
}
}
// My forEach function:
$$$={
any: function(array, callback){
array.forEach(function(value){
// console.log(value)
if (callback(value)) {
return true;
}
// return false;
})
return false;
}
}