Trying to process all results of an array nodes from a function but nothing was added to promises.
const promises = nodes.map(localModelScan);
function localModelScan(node) {
let text = node.textContent;
model.then(function (res) {
if(res.check(node.text) > 0.3) return node;
}).catch((error) => {
console.error('Error:', error);
});
}
You need to have return model; at the end of your localModelScan function, otherwise promises will just be an array full of undefined.
const promises = nodes.map(localModelScan);
function localModelScan(node) {
let text = node.textContent;
return model.then(function (res) {
if(res.check(node.text) > 0.3) return node;
}).catch((error) => {
console.error('Error:', error);
});
}
Alternatively, you can write this as an arrow function:
const localModelScan = (node) => model.then((res) => {
if(res.check(node.text) > 0.3) return node;
}).catch((error) => {
console.error('Error:', error);
});
const promises = nodes.map(localModelScan);