No title Revision 656135373634 (Mon Mar 08 2010 at 08:33) - Diff Link to this snippet: https://friendpaste.com/6sYxT4cNJ9IjpWiW9qgCut Embed: manni perldoc borland colorful default murphy trac fruity autumn bw emacs pastie friendly Show line numbers Wrap lines 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990MAP===Date.prototype.setRFC3339 = function(dString){ var regexp = /(\d\d\d\d)(-)?(\d\d)(-)?(\d\d)(T)?(\d\d)(:)?(\d\d)(:)?(\d\d)(\.\d+)?(Z|([+-])(\d\d)(:)?(\d\d))/; if (dString.toString().match(new RegExp(regexp))) { var d = dString.match(new RegExp(regexp)); var offset = 0; this.setUTCDate(1); this.setUTCFullYear(parseInt(d[1],10)); this.setUTCMonth(parseInt(d[3],10) - 1); this.setUTCDate(parseInt(d[5],10)); this.setUTCHours(parseInt(d[7],10)); this.setUTCMinutes(parseInt(d[9],10)); this.setUTCSeconds(parseInt(d[11],10)); if (d[12]) this.setUTCMilliseconds(parseFloat(d[12]) * 1000); else this.setUTCMilliseconds(0); if (d[13] != 'Z') { offset = (d[15] * 60) + parseInt(d[17],10); offset *= ((d[14] == '-') ? -1 : 1); this.setTime(this.getTime() - offset * 60 * 1000); } } else { this.setTime(Date.parse(dString)); } return this;}; function(doc) { if (doc.doc_type=="EdoPing" && doc.em_type==0) { date = new Date().setRFC3339(doc.created_at); var key = doc.em_uname + String(doc.created_at).substring(0,10); emit([doc.created_at.substring(0,10) ] , [doc.em_uname, 1] ); }}REDUCE======function(keys, values, rereduce) { var ucount = 0; var seen = new Object(); if (!rereduce) { // This is the reduce phase, we are reducing over emitted values from // the map functions. // we count 1 if a given uname has not been seen for(var i in values) { if (seen[values[i][0]] == undefined) { seen[values[i][0]] = 1; ucount += 1; } } } else { // This is the rereduce phase, we are re-reducing previosuly // reduced values. for(var i in values) { // loop around seen object values for(var j in values[i][1]) { if (seen[j] == undefined) { seen[j] = 1; ucount += 1; } } } } return [ucount, seen]; } ========== ["2010-03-03"] [1, {student1: 1}]["2010-03-04"] [1, {student1: 1}]["2010-03-05"] [1, {eong: 1}]["2010-03-06"] [3, {jfrancillette: 1, bkante: 1, mlouviers: 1}]["2010-03-07"] [1, {student1: 1}]