I have a function that checks to see if a node in my project has real words for it's name. The return statement returns before the foreach loop finishes causing the output to always be false. How can I make the return statement wait for the forEach loop to finish and then return the value?
const hasUnacceptableName = (node) => {
const words = extractWords(node.name);
let containsUnacceptableWord = false;
words.forEach((word) => {
//assume that this returns true
if (someFunctionThatReturnsTrue(word)) {
containsUnacceptableWord = true;
}
});
return containsUnacceptableWord;
}
via Shayan Javadi
No comments:
Post a Comment