Since graduating from coding boot camp, I’ve been focusing most of my time on building apps and websites; which is good for a resume but what about the actual interviewing process? Most developers I’ve spoken with have applauded this approach but have been quick to let me know that those apps won’t matter if I can’t pass algorithm questions that will most definitely be thrown my way. So today I am going to be sharing two common coding algorithms as well as their solutions and some links to resources that will help you expand your knowledge of algorithms.
FizzBuzz is definitely one of the most common algorithms you’ll be asked to solve. The instructions usually ask you to write a program that console logs or returns number 1 to n. If a number is divisible(or a multiple) of 3 - print ‘fizz’, a multiple of 5 - print ‘buzz’, a multiple of 3 and 5 - print ‘fizzbuzz’. For this solution, you’ll need to understand ‘for loops’, ‘if else’ statements, and the modulus(remainder) operator. The first item we should consider is how do we check that a number is divisible of any number. The modulus operator allows us to check what the remainder of a number will be.
The function will receive 10 as it’s variable then console log the result.
The result of the function, pictured above, will be 1. This is because 3 times 3 is 9 and the remainder of 9 into 10 is 1. So with that brief explanation, let’s build a statement to check if a number is a multiple of 3 and 5 (which must also be a multiple of 15).