No title Revision 326439363933 (Tue Sep 27 2011 at 03:37) - Diff Link to this snippet: https://friendpaste.com/3uiUREvtzHp6O02qe9p7Qn Embed: manni perldoc borland colorful default murphy trac fruity autumn bw emacs pastie friendly Show line numbers Wrap lines 12345678910111213141516171819202122232425262728293031323334353637383940414243/* Map function */function(doc) { if (doc.kind == "comment") { emit(doc.link_id, doc); }}/* Rereduce function */function (keys, values, rereduce) { var idx_comments = {}; var comments = []; if (rereduce) { return values; } else { for (var i=0; i<values.length; i++) { if (values[i]) { log({"_id": values[i]["_id"]}); idx_comments[values[i]['_id']] = values[i]; if (!values[i]['parents']) { comments=comments.concat(values[i]); } } } log("bouh!"); function iter_comments(lcomments, idx) { for (var i=0; i<lcomments.length; i++) { var comment = lcomments[i] || []; var thread=[]; if (comment['children'] && comment['children'].length > 0) { for (var j=0; j<comment['children'].length; j++) { if (!idx[comment['children'][j]]) { log({"don't exist?": comment['children'][j]}); } thread = thread.concat(idx[comment['children'][j]]); } comment['thread'] = iter_comments(thread, idx); } lcomments[i] = comment; } return lcomments; } tmp = iter_comments(comments, idx_comments); return tmp; }}