More Exercism.io JavaScript Challenges

I’ve been keeping detailed notes in this blog for all the exercism.io problems that I’ve solved so far, but I don’t want to give away the answers to all the practice problems! Besides, they’re getting a little repetitive now, and much of what I’m doing is just review. So I’ll only keep notes on the new things that I’ve learned. If a particularly new or challenging problem comes up, then maybe I’ll blog about it in detail.

I started on exercism.io challenge four, but I haven’t finished it yet. So far it’s been a good challenge! First, I learned what’s apparently called literal notation or initializer notation for initializing objects in JavaScript:

var myObject = {
    myProperty: someValue,
    myMethod: function(argument) {
        // do stuff        
    }
};

But I didn’t end up using that notation, because I find object constructor notation to be much easier to read:

function MyObject () {
    this.myProperty = someValue;
    this.myMethod = function(argument) {
        // do stuff        
    };
}

See this overview of JavaScript objects for more details on the different ways to define objects.

Second, I learned how to convert a string into an array of the string’s characters using the split() method:

var myString = "blah!";
console.log(myString.split(''));
// output: [ "b", "l", "a", "h", "!" ]

I also learned how to use the forEach() method for the first time! It’s just more compact than a for loop when you want to run a function on each element of an array.

And I re-learned how to use the break and continue statements to change the flow of a loop by either terminating the loop entirely or skipping ahead to its next interation.

I also learned how to use the arguments object to create a function that can take different kinds of inputs. Along with the isArray() method and the typeof operator, I can use this to create a function that can take either a string or an array as its input!

I really thought I could finish this problem before the end of the day, but I ran out of time. Tomorrow I’ll get it working for sure!