Junior Developer Toolbox

Episode 13 – The Sharpening

03.28.2018 - By Erin Orstrom & Dave HarnedPlay

Download our free app to listen on your phone

Download on the App StoreGet it on Google Play

In this episode, we dive a into some code katas and walk through a coding exercise. We’ll talk about sites we like to challenge ourselves with to keep our skills sharp.

What is a code kata? It’s a term for an exercise coined by Dave Thomas (not the Wendy’s guy) in the Pragmatic Programmer. The name kata is a Japanese word referring to the practice of martial arts. Code katas are short coding challenges, typically with a handful of tests to pass, that are a great way to practice.

Challenge websites we’ve used:

Freecodecamp

Codewars

Exercism

Hackerrank

 

For more, look here: https://medium.freecodecamp.org/the-10-most-popular-coding-challenge-websites-of-2016-fb8a5672d22f

 

Now we’re going to walk through a couple exercises together!

Is n divisible by … – from CodeWars

CodeWars Exercise – Step 1:

Capture the first argument passed in using the argument object. Set it to a variable (n).

CodeWars Exercise – Step 2:

In a for loop, iterate through the arguments object which will iterate through all of the parameters being passed in (we don’t know how many that will be, since it’s variable).

 

CodeWars Exercise – Step 3:

Using an if statement and modulo (%), check to see if n is divisible by each argument being passed into the function. If the result is not 0, return false, which breaks the loop and returns false for the whole function.

 

CodeWars Exercise – Step 4:

Return true outside of the for loop if n is divisible by all variables.

 

Keep in mind that there are many different ways to solve this exercise, and I may go back and refactor my solution at some point to make it more concise and use ES6.

 

Find the Longest Word in a String – from freeCodeCamp

freeCodeCamp Exercise – Step 1: Because I want to compare every word, I know I’ll need to iterate through them. The .split() string method can divide a long string into an array of smaller strings. I’m using the space between each word as a delimiter to neatly divide them all up.

freeCodeCamp Exercise – Step 2: I created a placeholder for the longest word length, initialized to zero. Then I’m going to use a .forEach() loop to iterate through one array item at a time, which I’ll refer to as ‘word’ in each iteration.

freeCodeCamp Exercise – Step 3: Now I want to compare each word’s length to my longest value, and if it’s longer, make that the new longest value. So I’m evaluating a conditional statement, and taking a different action depending on the result. There are a couple ways to do this, an “if / else” statement or a ternary operator.

More episodes from Junior Developer Toolbox