Skip to content

Instantly share code, notes, and snippets.

@JeffML
Last active January 11, 2017 04:38
Show Gist options
  • Save JeffML/3202cad046ab72d117760aa63c01027c to your computer and use it in GitHub Desktop.
Save JeffML/3202cad046ab72d117760aa63c01027c to your computer and use it in GitHub Desktop.
var _ = require('lodash');
var PouchDB = require('pouchdb');
var db = new PouchDB('choices');
db.allDocs({
include_docs: true
})
.then(docs => {
_.each(docs.rows, r => {
r.doc.taste = palatability();
db.put(r.doc);
});
});
function palatability() {
var scale = Math.round(Math.random() * 10);
var taste;
switch (true) {
// this switch is a horrible hack; don't ever do this ;-P
case (scale < 2):
taste = "ugh";
break;
case (scale < 5):
taste = "meh";
break;
case (scale < 8):
taste = "tasty";
break;
default:
taste = "sublime";
break;
}
return taste;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment