O'Reilly logo

Eloquent JavaScript by Marijn Haverbeke

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Solving the Problem of Aunt Emily's Cats

Coming back to those cats, we now know that an array would be a good way to store the archive of emails. If we assume that we have an array of email strings in the variable ARCHIVE, going over all the emails is simple now:

for (var i = 0; i < ARCHIVE.length; i++) {
  var email = ARCHIVE[i];
  // Do something with this email...
}

We have also decided on a way to represent the set of cats that are alive. The next problem, then, is to find the paragraphs in an email that start with “born” or “died.”

Separating Paragraphs

The first question that comes up is what exactly a paragraph is. In this case, the string value itself can’t help us much: JavaScript’s concept of text does not go any deeper than the “sequence of ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required