The purpose of this exercise is to count the number of vowels in a string. This is actually pretty easy using a regex expression. I use the match() method to pick out the vowels [aeiou]. The “g” in “/gi” tells the expression to match all occurrences, not just the first one. The “i” tells it […]
The goal of this problem is to take in a number (example – 4, and then print out that number of steps). There must be a space to pad out the rest of the character. Ex. n=4; loop 1 will be one # and three spaces for a total of 4 characters: # ## ### […]
In this problem, I am taking in a string and capitalizing the first letter of every word. Here I use a for…of loop. First I use the split() method to convert the string into an array and take the first letter of every word and capitalize it. Then I use the slice() method to add […]
Javascript regular expressions (regexp) are very useful methods for string manipulation — match, replace, search and split. I also find them pretty confusing. In the previous post on the Javascript anagram problem, I used the following regexp to remove all punctuation, etc. from a string: str.replace(/[^\w]/g,”). What does this actually mean? It’s hard to decipher a […]
I was working on a project for my web design course in late 2017, a website for newbie investors to track and learn about cryptocurrencies. I developed the site in React, so I had to use Javascript ES6 syntax. I have a method in my App component that would read in the current price of […]
This is the anagram problem I reviewed using Stephen Grider’s interview prep on Udemy. Amagram: a word, phrase or name formed by rearranging the letters of another, such as cinema from iceman (Google Dictionary). The challenge is to compare two sets of words or phrases to see if they contain the same number of each letter. Option 1 – […]
I worked this problem a couple of ways from both Stephen Grider’s Udemy Course and Traversy Media’s YouTube course. Below is solution 1. I use a for…of loop. First I determine what position the last element of the array would be (const last = chunked[chunked.length-1]). I have to use chunked.length-1, because length counts the number […]
This is the classic Javascript FizzBuzz problem where the task is to loop through n numbers and print “fizz” for multiples of 3, “buzz” for multiples of 5 and “fizzbuzz” for multiples of 3 and 5 (i.e. 15). This is a rather simple problem. The main thing is to test your knowledge of the modulo […]
Doing the Javascript reversed integer problem is pretty straightforward after doing the reversed string problem. The only extra steps are to convert the number into a string “.toString()”, then an array “.split(”) and “.reverse()” to reverse it. Finally, I need to use “.join(”) to convert it from an array back into a string, and “parseInt()” to […]
Here are a few solutions to the palindrome problem (a palindrome is a word that is the same spelled backward or forwards — like “racecar.” The objective is simply to return true if the word is a palindrome or false if it is not a palindrome. The solutions to this are pretty simple. I just […]