Permalink
Browse files

Update 06 - mongodb.md

  • Loading branch information...
1 parent f482439 commit 1b22ee39ccb7fac57f54daa63d293f62d5dab0a1 @duarten committed Feb 12, 2013
Showing with 17 additions and 8 deletions.
  1. +17 −8 06 - mongodb.md
View
@@ -66,32 +66,41 @@ Here you go:
i;
for (i = 0; i < maxDocuments; ++i) {
- var doc = {
+ var doc = {
title: titlePrefix[rand(titlePrefix.length)] + ' ' + titleSuffix[rand(titleSuffix.length)],
content: 'Yadda, yadda, yadda',
- date: (function(d) { return new Date(d.setDate(d.getDate() + rand(maxDocuments))); })(new Date()),
+ date: tap(new Date())(function(d) { d.setDate(d.getDate() + rand(maxDocuments)) }),
upvotes: rand(upvoteDelta) * tossCoin() ? 1 : -1,
tags: (function() {
var n = rand(tags.length),
ts = tags.length;
- return n > 1 ? randInts(n, ts).map(function(i) { return tags[i]; }) : tags[rand(ts)];
+ return n > 1 ? randInts(n, ts).map(function(i) { return tags[i]; }) : tags[rand(ts)]
})()
- };
+ }
if (tossCoin())
- doc.comments = ['Some Comment', 'Another Comment'];
+ doc.comments = ['Some Comment', 'Another Comment']
- db.blog.insert(doc);
+ db.blog.insert(doc)
}
function randInts(howMany, maxValue) {
var values = new Array(howMany),
i;
for (i = 0; i < howMany; ++i)
- values[i] = rand(maxValue);
+ values[i] = rand(maxValue)
- return values;
+ return values
+ }
+
+ function tap (value) {
+ return function (fn) {
+ if (typeof(fn) === 'function') {
+ fn(value)
+ }
+ return value
+ }
}
})();
```

0 comments on commit 1b22ee3

Please sign in to comment.