Week 27

Coding House: Week 7

Today marks the end of the first seven weeks of the Coding House program for our cohort. After a 3-day break, we’ll begin again on Monday in our new role as “code mentors”, essentially teaching assistants for the next batch of Coding House students. I’m really looking forward to meeting all of the incoming students, to having a chance to re-visit the material they’re working on, and to encouraging them as they debug, debug, and debug as I’ve been learning to do over the past two months.

This week was spent largely focused on learning more about user authentication, particularly through using third-party services like Firebase and Stormpath (we had a guest lecturer from Stormpath deliver a 5-hour workshop on Wednesday that was excellent). We’ve also spent some time doing mid-way assessments this week. One was an application challenge– we had 90 minutes to build a to-do app with Angular, and the other was a 3-hour Hacker Rank test today. I really love doing Hacker Rank challenges, and it was fun today to have a full 3 hours to devote to them. Though my initial response to most of the problems is still to reach for a for-loop, I can usually come up with alternative solutions as well with a bit more thought, something that wasn’t possible for me at the beginning of the cohort. The thing that was most enjoyable about today’s test, though, was that I spent the majority of the time refactoring my code and coming up with alternative solutions in order to make it more readable. Though I got all of the test cases to pass within and hour, I kept working for the rest of the time to clean up my code, and I feel pretty pleased with the changes I was able to make.
Here are a couple examples of the transformations:

// One challenge asked for a large multi-digit number to be transformed into a string with "*" characters between two even numbers
// and "-" characters between two odd numbers, considering 0 neither even nor odd

// my original solution works but is nearly impossible to understand

function weirdNumSplitter(num) {
    var numArray = String(num).split('');
    var weirdString = '';

    for (var index in numArray){
        if (parseInt(numArray[index]) === 0){
            weirdString += numArray[index];
        } else if (parseInt(numArray[index]) % 2 === 0 && parseInt(numArray[index -1]) % 2 === 0 && parseInt(numArray[index -1]) !== 0) {
            weirdString += '*' + numArray[index];
        } else if (parseInt(numArray[index]) % 2 === 1 && parseInt(numArray[index -1]) % 2 === 1 && parseInt(numArray[index -1]) !== 0) {
            weirdString += '-' + numArray[index];
        } else {
            weirdString += numArray[index];
        }
    }
    return weirdString;
}

// And here's the refactored version:

function weirdNumSplitter(num) {
    var numArray = String(num).split('');
    var weirdString = '';

    for (var index in numArray){
        var currentNum = parseInt(numArray[index]);
        var prevNum = parseInt(numArray[index - 1]);
        var currentIsEven = (currentNum % 2 === 0);
        var prevIsEven =  (prevNum % 2 === 0);

        if (currentIsEven && prevIsEven && prevNum !== 0 && currentNum !== 0) {
            weirdString += '*' + currentNum;

        } else if (!currentIsEven && prevNum % 2 === 1) {
            weirdString += '-' + currentNum;

        } else {
            weirdString += currentNum;
        }
    }
    return weirdString;
}

// I also wrote this again using a map, just to try another approach:

function weirdNumSplitter(num) {
    var numArray = String(num).split('');
    var weirdString = numArray.map(changeChar).join('');

    function changeChar(char, index) {
        var currentNum = parseInt(char);
        var prevNum = parseInt(numArray[index - 1]);
        var currentIsEven = (currentNum % 2 === 0);
        var prevIsEven =  (prevNum % 2 === 0);

        if (currentIsEven && prevIsEven && prevNum !== 0 && currentNum !== 0) {
            return '*' + currentNum;

        } else if (!currentIsEven && prevNum % 2 === 1) {
            return '-' + currentNum;

        } else {
            return currentNum;
        }
    }

    return weirdString;
}

Week 7 projects/coding assessment:

Firebase chatroom app:
on github: https://github.com/bolducp/angularFirebaseChatroom
live on gh-pages: http://bolducp.github.io/angularFirebaseChatroom/#/

90-minute coding assessment (build a MEAN stack to-do app)
on github: https://github.com/bolducp/toToAppCodingTest
live on heroku: https://polar-ravine-30366.herokuapp.com/#/

Week 7, Main Topics:

  • More Angular JS
  • custom form validation with Angular
  • Angular Fire
    • realtime database storage
    • chatroom functionality
    • user authentication
  • NPM packages
    • bcrypt-node
  • user authentication using headers
  • web scrapping
  • Stormpath
Advertisements

One thought on “Week 27

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s