« Back to home

Vowels

This exercise will be a walk in the park. We need to do a case insensitive count of vowel characters in a given string. In this exercise we’ll try to use map(), filter(), and reduce(). This is going to be a fun one. Starting like we always do, go to our exercises/ directory and create our new directory, vowels/ and create two files index.js and test.js. We’ll add some prebaked tests into the test.…

Read more »

Pyramid

Building on our last exercise this time we’re going to be building a pyramid. Given a positive number print that number of lines printing out a pyramid shape: pyramid(3) => ‘ # ’ ‘ ### ’ ‘#####’ You should be able to see the similarities in the output - but the program will have to do a little more work to figure out if it needs to print a space or hashtag.…

Read more »

Steps

Ok, next up on our list of exercises is going to be to create a steps(n) function. This function will print out to the console a number of log statements like so: steps(3) => ‘# ’ ‘## ’ ‘###’ Meaning the base will print N “#” signs, and any steps above will have a single space to the right for each step up when given a positive number. Following the same approach, we’ll navigate to our exercises/ directory and create a new directory called steps/, then we’ll jump into the directory and create our index.…

Read more »

Capitalizer

This particular exercise should be a breeze after some of the exercises that we’ve already gone through. Given a string, capitalize the first letter of each word in that string. Once again, we have some setup to take care of - creating our directory and files. mkdir capitalizer && cd capitalizer/ && touch index.js test.js Then get some tests into our test.js file: const capitalize = require(‘./index’); test(‘Capitalize exists’, () => { expect(typeof capitalize).…

Read more »

Anagram Check

It’s time to work through another (easy) exercise in javascript. This time we’ll be working through an anagram checker function. Just so that we’re all on the same page I’ve taken the liberty of pulling up an official definition of “anagram”: > a word, phrase, or sentence formed from another by rearranging its letters: “Angel” is an anagram of “glean.”. Pretty much what we are about to set out to do is see if the letters contained within the two string parameters match.…

Read more »

Array Chunk

Today we’ll be working through an exercise where the input is an array [1,2,3,4,5] and a size 2. Based on that input our goal is to write a function that will take the original array and return a new multidimensional (nested) array with the elements each of the size param that was passed in. It’ll probably be easier to understand based on this example: chunk([1,2,3,4,5], 2) => [ [1,2], [3,4], [5]] This problem should be easier to reason about now that we’ve seen a example.…

Read more »

Fizzbuzz

Our next exercise is going to be Fizzbuzz. This is a pretty common exercise that’s pretty simple. Let’s get started! Same like we always do, we’ll create a new directory from inside our exercises directory to hold our tests/code and create a couple files - index.js test.js. mkdir fizzbuzz && cd fizzbuzz/ touch index.js test.js Using your mechanism of choice we’ll get the following content into your test.js file:…

Read more »

Return Max Char

Today we’re going to be writing a function that will return the most frequent character that appears in a string. Given the string: “abcdd” we would get back “d” because that character appears twice whereas the other characters only appear once. This function would work the same when working with numbers, which will be coming in as a string anyways. We can create our new directory inside of our exercises directory as well as our two files, index.…

Read more »

Javascript More String Exercises

Next up on our list of exercises is going to be two more simple functions. First we’ll walk through how to implement a palindrome checker, and then we’ll cover reversing integers. For the palindrome function, we’ll want to return true/false depending on whether or not a given string is a palindrome. For those of you who are not familiar with the term here is the definition: a word, phrase, or sequence that reads the same backward as forward…

Read more »

Javascript Reverse String

In an effort to learn the in’s and out’s of ES2017 I’m going to be working through some exercises. The first exercise I’d like to work through is a pretty simple one, reversing a string with javascript. Basically, given string ‘foobar’ I’d like to return ‘raboof’ - again, this is pretty simple and I think it would be a great place to start. To start with, let’s go ahead and create a new directory in our terminal with:…

Read more »