Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update 06 - mongodb.md

  • Loading branch information...
commit c1e91583c30570fc9470eb699bccdc146d375ea2 1 parent 5af7c05
@duarten authored
Showing with 12 additions and 13 deletions.
  1. +12 −13 06 - mongodb.md
View
25 06 - mongodb.md
@@ -61,27 +61,27 @@ Here you go:
tags = ['omg', 'humm', 'wtf'],
upvoteDelta = 16,
maxDocuments = 10,
- rand = function(max) { return Math.floor(Math.random() * max) },
- tossCoin = function() { return rand(2) > 0 },
+ rand = function(max) { return Math.floor(Math.random() * max); },
+ tossCoin = function() { return rand(2) > 0; },
i;
for (i = 0; i < maxDocuments; ++i) {
var doc = {
title: titlePrefix[rand(titlePrefix.length)] + ' ' + titleSuffix[rand(titleSuffix.length)],
content: 'Yadda, yadda, yadda',
- date: tap(new Date())(function(d) { d.setDate(d.getDate() + rand(maxDocuments)) }),
+ 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) {
@@ -89,18 +89,17 @@ Here you go:
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
- }
+ if (typeof(fn) === 'function')
+ fn(value);
+ return value;
+ };
}
})();
```
Please sign in to comment.
Something went wrong with that request. Please try again.