I am re-reading Eloquent Javascript with Arthur at the moment, and realizing how much of a mistake I made reading it the first time around — that is, I read it by myself, barely typed out any of the exercises before looking at the solutions, and skimmed past sections when it got confusing.


(Although you can purchase this book online, it’s free to read online.)

Arthur isn’t a programmer in the career sense, but he double majored in math along with italian, and apparently having had practice solving mathematical problems helps a lot.

Having a study partner also helps a lot. As we read, we’ll paraphrase the content out loud, quiz each other about what we just read, google an answer when the answer to a question isn’t immediately apparent, work on the exercises individually, share our respective solutions to the exercises using JSFiddle, and puzzle out root causes when something we coded renders something surprising.

For example:

split and join are not precisely each other’s inverse. string.split(x).join(x) always produces the original value, but array.join(x).split(x) does not. Can you give an example of an array where .join(” “).split(” “) produces a different value? – Exercise 4.3

We each approached the solution differently:

var testo = ["This is a", "sentence Arthur wrote."];
console.log(testo.join(" "));
console.log(testo.join(" ").split(" "));
array = ["this", "is ", "a", "sentence", "Linda", "wrote", "with", "an", "extra", "space", "after", "is"];
console.log(array.join(" "));
console.log(array.join(" ").split(" "));

To solve this, we had to truly understand what the .join() and .split() methods did in javascript.

There’s good documentation on Mozilla:
“The join() method joins all elements of an array into a string.”

In other words, you start with an array, and you turn it into a string!

“The split() method splits a String object into an array of strings by separating the string into substrings.”

In other words, you split a string up into an array!

The two methods are not exact opposites of each other, though, as we just demonstrated via the book exercise.

blog comments powered by Disqus
  • Hi, I'm Linda! I enjoy going to tech meetups, learning web development, and blogging about the learning path. Follow me @LPnotes

Subscribe to The Coding Diaries