(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.
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(" "));
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.