I have two functions below (they are taken out of a larger script so assume everything is defined etc. self.sentenceObjs
works great. It returns an object exactly like it's supposed to do. self.parseBodySections
for some reason sets bodyJSON
to an array of undefined
even though self.sentenceObjs
is returning perfect objects given the dom
array of objects I want mapped. For some reason when I run dom.map(self.sentenceObjs)
it returns undefined for each object. Any idea why this would be? Is there something with Array.map()
that I missing?
self.parseBodySections = function(dom, cb) {
var bodyJSON = dom.map(self.sentenceObjs);
console.log(bodyJSON); // prints: [ undefined, undefined, undefined, undefined, undefined ]
return cb(null, bodyJSON);
};
self.sentenceObjs = function(section) {
var paragraphToTextAndLinks = function(cb) {
return self.paragraphToTextAndLinks(section.children, function(err, paragraphText, links) {
if (err) {
return cb(err);
}
return cb(null, paragraphText, links);
});
};
return async.waterfall([
paragraphToTextAndLinks,
self.paragraphToSentences
],
function(err, sentences, paragraphPlaintext) {
var paragraph = {
type: section.name,
value: paragraphPlaintext,
children: sentences
};
console.log(paragraph) // prints perfect object (too long to show here)
return paragraph;
});
};
waterfall
return? I'm not very familiar with the library but by reading at the docs it seems like it doesn't actually return the compound of the functions, it exposes it into a callback. Can you checkconsole.log(async.waterfall([...
and see what it outputs? – elclanrs 21 hours agoundefined
. I'm pretty new to the library myself so I'm probably misunderstanding something. – chromedude 21 hours agoparseBodySections
inside the callback ofwaterfall
, not the other way around, sincewaterfall
is the asynchronous part. I may be wrong tho... – elclanrs 21 hours ago