Skip to content

Instantly share code, notes, and snippets.

@slopeofhope81
Created February 5, 2014 14:53
Show Gist options
  • Select an option

  • Save slopeofhope81/8825339 to your computer and use it in GitHub Desktop.

Select an option

Save slopeofhope81/8825339 to your computer and use it in GitHub Desktop.
Write a function extractDate that takes such a paragraph as its argument, extracts the date, and returns it as a date object.
//"died 27/04/2006: Black Leclère"
var p = "died 27/04/2006: Black Leclère"
function extractDate(p) {
function find(start, length) {
return p.slice(start, start + length)
}
return new Date(find(11, 4), find(8, 2) - 1, find(5, 2))
}
Here I used nested functions! I am starting to understand when to use nested function inside the outer function that is famously called closure!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment