Write a function that accepts a callback method and returns a function that will execute only if all the parameters passed to it are defined, otherwise it returns nothing. Here's what I wrote why is not it working?
function sumof(checkof) {
sum = 0
for (a in this.myNumbers)
if (checkof(a) == 1)
sum += a
else
return null
return sum
}
function check(a) {
if (a == null)
return 0
else
return 1
}
function init() {
let myNumbers = [22, 1, 8, 4, 17];
var x = myNumbers.sumof(check)
alert(x)
}
init()
myNumbers.sumof(...)would work?)sumof(myNumbers)\