Skip to content

Instantly share code, notes, and snippets.

@chrisdickinson
Created February 5, 2013 18:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chrisdickinson/222d7d06ce200f717c19 to your computer and use it in GitHub Desktop.
Save chrisdickinson/222d7d06ce200f717c19 to your computer and use it in GitHub Desktop.

Project 2

Part 1:

Write a module -- README, tests, and all -- that exports a function that takes a string and returns a function that takes an object that returns a string.

Whew. That's a mouthful! What we're looking for, in other words, is something that does this:

var dotpath = require('your-module-name')

var find = dotpath('part.key.attribute')

var found = find({part: {key: {attribute: "woop woop"} }})

console.log(found) // outputs "woop woop"

var not_found = find({}) || find() || find(null)

console.log(not_found) // outputs undefined

Once you're done and you've got tests, publish your module on NPM.

Part 2:

Open up the last project ("A tiny templating language"). Use npm install --save <yourmodule> to make the module you just wrote available.

Bonus points:

Rewrite the first module, now that you have tests. Do not use any loops.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment