Showing posts with label factorial. Show all posts
Showing posts with label factorial. Show all posts

Saturday, August 27, 2016

More Free Resources

I recently got a hold of some questions asked by the schools I want to attend during their preliminary coding challenges. Let's just say some were very, very hard.

I did one set of problems for one school and felt great! I was able to answer all three with very little effort and time, which of course was a huge relief. However, on the other exam I was able to fully answer ONE out of FIVE. I was almost done with the second and was able to write some pseudo code for the third, but by the end of my time I barely understood what the last two were asking from me. It was a huge blow.

Since then I've been researching, practicing, learning everything. From refreshing on my basics from 'A Smarter Way to Learn Javascript', to exploring completely new topics that have helped me solve the problems that once bamboozled me.

All in all, things have been progressing over on my end and I hope they are on yours as well! Today I just have a couple more links I've found while trying to learn on my own.

funfunfunctions: This guy is a little goofy and he codes using ECMA6 which at times is a little confusing since I'm still learning vanilla javascript, but he explains things pretty well and hates fibonacci sequences more than I do (which I didn't think was possible). He has some great videos covering more "basics" of javascript that really help push your code to the next level.

Codesmith.io: Codesmith is a dev bootcamp based out of LA. I discovered them while doing some research on course report and found that they offer **FREE** workshops titled 'JS: The Hard Parts'.
It's an in-person workshop you can sign into and participate in via youtube. You can even pair-program with a virtual partner (for which I am currently taking applications). The workshops are held weekly on Thursday nights and really tackled some of the tough stuff these coding schools would like their applicants to be aware of.

That's all for now! Stay tuned for the debut of an awesome website the boy and I are working on :)

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: