I have a function which checks some parameters and returns either true/false accordingly.
My problem is that it returns true (the last return true;), but then when I call this function again and it gets to console.log(return 1) or console.log(return 2),the function only executes the console.log() and then returns undefined instead of true or false. My assumption is that its not allowed to return from .map() unless its finished running?
isFlashingUnderscore() {
let count = 0;
if (!_.isEmpty(this.currentElement.value)) {
_.map(Object.keys(this.currentElement.value), key => {
count++
if (this.currentElement.value[key].object_type == 'date_range') {
return false;
} else if (this.currentElement.value[key].object_type == 'date') {
if (count >= 2) {
console.log('return 1');
return false;
} else {
console.log('return 2');
return true;
}
} else {
return true;
}
})
} else {
console.log('returns this true')
return true;
}
}
returnstatements inside the_.map()call return only from the callback function, not the outer containing function.trueorfalsefrom_.map()? I would have to set a variable totrueorfalseand then return it from the outer function?_.map? You're not actually doing a mapping operation you seem to be using it for simple iteration which is not its purpose. What's the goal here?