Monday, May 30, 2016

a/A Practice Problems: Sum Nums

This one is pretty straight forward. The only thing to look out for: for loop starting with num and decreasing each time.

Problem: Write a method that takes in an integer 'num' and returns the sum of all integers between zero and num, up to and including num.


Game Plan: 
>>  function takes in one parameter, num.
>>  for loop to go through each number below (and including) num (i--).
>>  declare variable and set it equal to 0, will hold value from each iteration of loop.
>>  return total sum


Step 1: 

                                                        function sumNums(num) {
                                                        }

Step 2:

                                                       function sumNums(num) {
                                                          var sum = 0;
                                                       }

Step 3:

                                                        function sumNums(num) {
                                                           var sum = 0;
                                                           for (var i = num; i > 0; i--) {
                                                           }
                                                        }

Loop starts with num and stops when it is greater than 0, or 1.

Step 4: 

                                                         function sumNums(num) {
                                                            var sum = 0;
                                                            for (var i = num; i > 0; i--) {
                                                               sum += i;
                                                            }
                                                         }

You could also write sum = sum + i;

Step 5:

                                                          function sumNums(num) {
                                                             var sum = 0;
                                                             for (var i = num; i > 0; i--) {
                                                                sum += i;
                                                             }
                                                             return sum;
                                                          }


Check out past problems here:

Sunday, May 29, 2016

a/A Practice Problems: Longest Word

This problem was a tricky one. Despite its "easy" rating, I struggled with it for a little thinking of the most roundabout ways of answering, including multiple nested for loops-- which as you can guess was just a joy ride. Maybe possible, but that way would have taken me forever to write and would have probably been very error prone. The hardest part for me turned out to be knowing how to set it up. How could I solve this so that I didn't need to go through every character of a string? Well, you don't want to go through every character necessarily (my first mistake), but rather every word. But I'm getting ahead of myself...

Problem:  Write a method that takes in a string. Return the longest word in the string. You may assume that the string contains only letters and spaces. You may use the 'split' method to aid you in your quest.

Game Plan: 
>>  Function that has one parameter (string) in this example.
>>  How can you quickly separate each word? Split method. The result of which will return an array of all the words. You'll want to set this equal to some variable for easy access later.
>>  For loop to go though each word to determine if it's the longest.
>>  This is where I got sort of lost-- I knew I needed to do all the above steps, but I didn't know how to keep track of which word was longest. If you had one independent variable to compare each word to, wouldn't that be easier than making some sort of March-Madness bracket system where you compare every word to each other? Methinks yes. So in order to do that, I'll set a variable equal to 0. The way the loop will work : compare the first word's length to 0, if the word is bigger (which it will be since it will be at least one letter character), i'll save the length of that word to the variable. As the loop progresses it will compare each word to this variable, saving the larger of the two.
>>  if statement to compare lengths
>>  Return longest word

Step 1:

                                             function longestWord(string) {
                                             }

Step 2:

                                             function longestWord(string) {
                                                var words = string.split(" ");
                                             }

Make sure there's a space between your quotes so that it knows where to split the string. If you didn't include the space, you would get each individual character at each index.

Step 3:

                                             function longestWord(string) {
                                                var words = string.split(" ");
                                                var longest = 0;
                                             }

We declare this variable, so that we don't need to compare each word to each other, but rather one independent variable.

Step 4:

                                            function longestWord(string) {
                                               var words = string.split(" ");
                                               var longest = 0;
                                               for (var i  = 0; i < words.length; i++) {
                                               }
                                            }

Remember when you split the string, it results in an array of all the words so we can use the array's length.

Step 5:

                                             function longestWord(string) {
                                                var words = string.split(" ");
                                                var longest = 0;
                                                var longIndx = 0;
                                                for (var i  = 0; i < words.length; i++) {
                                                   if (words[i].length > longest) {
                                                      longest = words[i].length;
                                                      longIndx++;
                                                   } 
                                                }
                                             }

The tricky part-- if the length of the word at index i is greater than longest (0), then we change the value of longest to the length of that word. AND since we want to keep track of which word we are on, we can set a marker of sorts at 0 (longIndx) that will increase if the word at position i is greater than longest. The value will let us know the index number of the longest word so that we can call it later.

Step 6:

                                             function longestWord(string) {
                                                var words = string.split(" ");
                                                var longest = 0;
                                                var longIndx = 0;
                                                for (var i  = 0; i < words.length; i++) {
                                                   if (words[i].length > longest) {
                                                      longest = words[i].length;
                                                      longIndx++;
                                                   }
                                                 }
                                                 return words[longIndx];
                                              }


Try it yourself!

Check out past problems here:

Thursday, May 26, 2016

a/A Practice Problem: Factorial

Challenge Description: "Write a method that takes an integer 'n' in; it should return
n*(n-1)*(n-2)*...*2*1. Assume n >= 0. As a special case, factorial(0) == 1"

Quick refresher on factorials: say n = 5, a factorial would be the product of 5*4*3*2*1 or 120.

Step 1: Write out your plan of action:

                         >> make function with one parameter
                         >> declare variable and set equal to 1
                         >> for loop to take each number less than n and multiply to variable
                         >> if statement for if n = 0
                         >> return product

Step 2: Declare function. Same rules for naming variables.

                                                  function factorial(n) {
                                                  }

Step 3: Set variable and set equal to 1.

                                                   function factorial(n) {
                                                      var product = 1;
                                                   }

Step 4: For loop with descending counter: Set i equal to n because you want to make sure it's the first number to start with and is included. The loop should stop once it hits one, or when i is greater than 0. Decrement by one each time to include each number below n (and over 0).

                                                    function factorial(n) {
                                                      var product = 1;
                                                      for (var i = n; i > 0; i--) {
                                                      }
                                                    }

Step 5: If statement for if n is 0; else multiply i to the variable product. The loop will start with n and every time it will be multiplied to the variable product.

                                                     function factorial(n) {
                                                       var product = 1;
                                                       for (var i = n; i < 0; i--) {
                                                           if (n === 0) {
                                                              product = 1;
                                                           } else {
                                                              product *= i;
                                                           }
                                                       }
                                                     }

Step 6: Return the variable product: because you have to return the answer...

                                                     function factorial(n) {
                                                        var product = 1;
                                                        for (var i = n; i < 0; i--) {
                                                           if (n === 0) {
                                                              product = 1;
                                                           } else {
                                                              product *= i;
                                                           }
                                                        }
                                                        return product;
                                                     }

There you have it! Any comments or questions are all appreciated.

Check out past problems here:

Wednesday, May 25, 2016

a/A Practice Problems: Reverse a String

When I had first learned about App Academy I quickly tried to learn everything I could to solve those damned practice problems. Short story shorter, I could not wrap my mind around the first one. I came back to it the other night, however, and with all my new fandangled Javascript skills I was able to take on more than a couple. SHABOOYAH. What really helps me when I am learning something new is seeing the process someone went through to solve the challenge at hand, in this case reversing a string without using the reverse method. Because I found so few resources like that initially, I thought to do it myself and hopefully be that source for someone else.

Note, App Academy is a Ruby/Rails school, but if I read correctly they'll allow you to answer challenges in whichever language you choose -- obviously I'll be doing all these in JS.

Your mission: "Write a method that will take a string as input, and return a new string with the same letters in reverse order"

Disclaimer: This is my methodology, there are many other ways to do this; most likely there better ways to do this. But I'm a noob, so shut it.

Step 1: Write out what you need to do. It's like a game plan or blueprint to getting the answer. It helps me to really think about what the question is asking so that I can answer appropriately. This one is pretty straightforward.

     >> have to be able to accept input (function via arguments/parameters) 
     >> pinpoint last letter of string (1 less than length)
     >> run through & return letters from last character (loop with descending counter)
     >> return reversed string

Step 2: Define the function. Only rules that apply are the same for that of variables. (no numbers, symbols to start off; contains only letters, numbers, $ and _). Set up function to accept one parameter, "word" in this example.
  
function reverseString (word) {}

 Step 3: Find last character of string. I set the value equal to a new variable, lastChar so that it's easier to access. Remember indexes start with 0 (hence the minus 1).

                                                       function reverseString(word) {                                                  
                                                         var lastChar = word.length - 1;
                                                        }

Step 4: For loop with descending counter. Instead of setting i = 0, I set it to lastChar so that it would start with the last letter of the string; i >= 0 tells the loop to stop once it reaches the index 0, first letter of the string; i-- tells the loop to decrement by one each time.

                                              function reverseString(word) {
                                                 var lastChar = word.length - 1;
                                                 for (var i = lastChar; i >= 0; i--) {
  
                                                 }
                                              }

Step 5: Concatenate. If we were to give ourselves a test case, say reverseString("abc");, and if we were to console.log(word[i]) we would see that each letter would come back in reversed order. Hooray! But, (boo!) it wouldn't come back in one string, "cba". To fix this, I thought do declare another variable (empty this time) and then add each letter to it, aka concatenate it into one. The code block inside the for-loop is telling the function to add each letter to the variable newString. I'm not sure why you would use bracket notation for a string when they're reserved mostly for arrays, but I know it works and that they operate similarly and that's the best explanation I can give.

                                              function reverseString(word) {
                                                 var lastChar = word.length - 1;
                                                 var newString = "";
                                                  for (var i = lastChar; i >= 0; i--) {
                                                     newString += word[i];
                                                           
 // same as newString = newString + word[i];
                                                  }
                                              }

Step 6: Return newString. Now that we have all the working parts, the only thing left to do is to return the reversed string. Remember to put this after the function.

                                              function reverseString(word) {
                                                var lastChar = word.length - 1;
                                                var newString = "";
                                                 for (var i = lastChar; i >= 0; i--) {
                                                     newString += word[i]; 
                                                 }
                                                 return newString;
                                              }

If you were to type this into your console or whatever environment, you should get "cba". There you have it, guys! Comment with any questions or if you have any techniques that would solve this quicker, I'd love to read it. Good luck!

Friday, May 20, 2016

My 3 Favorite Free Resources to Learn Javascript

When I started this blog (a whole 4 posts ago), I was focused on learning Ruby. Since then I've switched gears because the school I will be applying to focuses solely on, you guessed it, Javascript. I hope to visit Ruby again in the future, but for now I'm all bout those curly braces. Woo.

I've had some success in learning the language. Thanks to the interwebs and all the free resources I've been using, I feel pretty good about where I'm at so I wanted to share what's helped me.

  1.  A Smarter Way to Learn by Mark Myers.
    This book was recommended to me by a friend and has since become the basis of all my understanding. The way Myers explains things is pretty straightforward and everything builds on itself almost perfectly. Every chapter-- only 89 --  lasts a couple of pages, 5 maybe at most and once you're done there are practice problems associated with each chapter to test your newly acquired knowledge. While the book focuses on many different concepts, it does so in pretty basic ways, but this is to ease you into the language and help you to actually understand the fundamentals.

  2. Codewars
    When I first heard of Codewars I was eager to sign up. Be aware, there are two problems you have to answer right to actually become a part of the site, but once you are it's great! It works like Karate in that you start at the beginner levels denoted by higher numbers (8 kata) and work your way down (or up) to 1, at which time you can be a self-proclaimed Jedi coding wizard. You can target what you want to work on: fundamentals, algorithms, logic, loops, etc, in every level and go from there. You earn honor or "kata" for every question you answer right and it's a great way to test or refine your skills. As far as negatives go, it can be really self-defeating. Sometimes the challenges themselves aren't written correctly and so you can't get the points even though your answer is right. Other times it serves as a humble reminder that you might be a long way from where you want to be. But don't get discouraged! If you can't solve a problem and it's eating away at you (a common thing 'round these parts) forfeit the kata and read some solutions (only visible when you forfeit or answer correctly). See what others have posted and you might find that the answer was well within your reach, and you will start getting better. Remember: wax on, wax off.

  3. YouTube
    My biggest struggle with learning to code on my own was a lack of resources out there after the plethora of pure beginner sources. I was having a hard time translating what I had learned into actual working programs. Step in YouTube: the world's best guidebook for any and all things. While I have had some trouble finding a video that explains the exact problem I'm working on, I have found some really helpful tutorials that lead me the right way. The user, kudvenkat, has been one of my personal favorites, but there are seriously endless amounts of people out there willing to help. Another personal fave: LearnCode.academy.
Of course this list is not exhaustive, and as such I have a few others I'd like to shout out: 
Honorable mentions: w3schools, devtools and stackoverflow.

My hope is that this helps someone else out there, but know there are so many other people and resources willing to help if this particular list doesn't work for you. Go and get on with your bad self.

Happy Friday, friends!

Tuesday, May 17, 2016

Surviving Your First Hackathon: A Cleverett Girl's Guide

Like I mentioned last time, I recently participated in my first Hackathon. It was part of the eMERGE Americas conference, which ended up being pretty freaking sweet. What is it about really successful people admitting they've totally screwed up that is so inspiring? Another post for another time perhaps.

Anyways! So my first hackathon. I wasn't nervous until I got there and saw all the other very eager coders, representatives from Facebook and Visa (to name a couple) that I started to get really antsy. I had never seen a room so packed with people who do what I want to do; a room so packed with people who take what I want to do so seriously. In a word, it was overwhelming as shit. So, I came up with some pointers that may or may not help another noob out there about to experience their first hackathon.

1. Know Your Strengths.
Only you know what you can and cant do. A hackathon is a great time and place to test out some newly acquired skills or just hone in on things you already know. But if you're working with a team, it's best to know how you can best contribute. That means working with what you already know. If you know back-end DO back-end, if there are two of you working on the back-end, that would be a great time to try out peer programming. The point is this: don't say you're going to make the iOS version of your project when you've never even attempted a Swift tutorial.

2. Have a vision.
Nothing is worse than being awake, in full spirits, ready to work and not having anything to work on. Especially since your attention and focus will only wane when the hours get longer. You want to have an idea that you want to pursue. Really legit teams will have already drawn up a map (totally permissible) detailing how the app will function. A clearly conveyed idea will help you and your team get off on the right foot and will propel you when time gets slower and slower and slower. And trust me, it does.

3.  Be realistic.
It's easy to shoot for the moon, especially when there's, say, $10,000 on the line. Who wouldn't want to win some serious cash!? Most hackathons will give you some sort of criteria that you need to follow to qualify for the prizes. For eMerge all we needed to do was include a Visa API in. We started thinking of ideas that we would love to use in our daily lives and while all were great... it was just downright unrealistic to build out some of them when we had already spent more than an hour just thinking of an idea. Simplicity is your friend. Take a simple idea and bedazzle the shiz out of it. Make it really awesome. It isn't about the idea per say, it's about the execution of the idea.

4. Communication is key:
Waffleboards are your best friends. Keep an open dialogue with your teammates, let them know what you're working on, what you're having trouble with, what you've finished and going to work on next. Being on the same page with everyone will save you minutes which can add up in the end. And when you and the rest of your team are stumped on a specific problem, don't be afraid to reach out to other contestants-- most of the people there are more than happy to help (or humble brag but whatevs). We actually ended up coding with some other non-team members after they offered to help us out. Smart and friendly people rock.

And there you have it. This is certainly this is not a comprehensive guide, but a lil' something from me to you. I did forget to mention one thing: don't forget to have fun. That's what these things are all about, the small, local ones that is. ;)