Let’s write a function that returns the number of vowels (aeiou) used in a string. Although ‘y’ is sometimes considered a vowel, I’m going to leave it out. The way we write our function will allow us to return the count of any character we choose, whether it be all vowels, including ‘y,’ consonants, or any variety of numbers and letters.
Here’s an example of what we’re going for:
vowels("Hi There!");// 3
When the #vowels function is called with the string argument, ‘Hi There!’ it returns 3, since there is one ‘i’ and two ‘e’s.
Here’s the function declaration…
Given an integer, return an integer that is the reverse ordering of numbers.
For instance —
reverseInt(15); // 51
reverseInt(981); // 189
reverseInt(500); // 5
reverseInt(-15); // -51
reverseInt(-90); // -9
In a previous post, I wrote about string reversal in JavaScript. We’re going to use a very similar solution to solve our reverse integer problem.
In order to reverse the integer let’s first turn it into a string using the toString() function, and set it equal to a new variable, reversed.
const num = 15;const reversed = num.toString(); reversed; // "15"
Then we’ll use split() with an empty…
The problem-
Given a string, write a function that returns the character that is most commonly used in the string. The string can contain numbers, uppercase letters, and lowercase letters.
Here’s our string.
const doozyOfAString = "1ttgmbpftDDY0dG31JlXMuigx0JV2Xu8Q9qx456Fy2XAGxgkGa7Uz37wDcdbfBcDr12C2Tdpg0YRbx3hBCWAKL1ck4x7T3elpiVW";
It’s a doozy of a string but a string nonetheless. Let’s get to work.
First, let’s create our function. It takes a string as a parameter and will return the max character.
function maxChar(str) { let maxChar = ""; return maxChar;}
My first instinct was to create a counter. Surely we’ll need to keep track of the number of times the max…
There are a bunch of ways to reverse a string in Javascript.
I’ve got a big mug of coffee next to me while writing this and it’s inspiring me. Let’s reverse the string, “coffee”. Here’s how to do it with magical built-in methods:
"coffee".split("").reverse.join("");// "eeffoc"
Let’s break that down.
The #split method turns a string into an array.
"coffee".split(); // ["coffee"]
In order to reverse each letter in the string, we have to pass #split an empty string argument (“”). This splits the string between each character.
"coffee".split(""); // ["c", "o", "f", "f", "e", "e"]
We can then chain…
Another day, another algorithm.
Here’s what the chunk function wants me to do: When given an array and chunk size, divide the array into many subarrays.
For example:
const array = [1, 2, 3, 4];
const chunkSize = 2;chunk(array, chunkSize);// [[1, 2], [3, 4]]
If there are extra elements in the array smaller than the chunk size, they should also get divided into a subarray.
const array = [1, 2, 3, 4, 5];
const chunkSize = 2;chunk(array, chunkSize);// [[1, 2], [3, 4], [5]]
Since I’m going to be returning a new array, I’ll create that variable…
What’s a happy number? Here’s how LeetCode describes one.
A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy numbers.
Here’s an example.
Input: 19
Output: true
Explanation:
1² + 9² = 82
8² + 2² = 68
6² + 8² = 100
1² + 0²…
The problem from Hackerrank:
“Gary is an avid hiker. He tracks his hikes meticulously, paying close attention to small details like topography. During his last hike, he took exactly n steps. For every step he took, he noted if it was an uphill, U, or a downhill, D step. Gary’s hikes start and end at sea level, and each step up or down represents a unit change in altitude. We define the following terms:
+ A mountain is a sequence of consecutive steps above sea level, starting with a step up from sea level and ending with a step down…
Arrays in Ruby have a lot of built-in methods. Some I use regularly, others sparingly, and the last chunk I’ve never touched. To learn them all, I’ve decided to dedicate a few blog posts to exploring array methods.
Of course, I couldn’t start discussing arrays in Ruby without first answering, “What is an array?”
An array is an integer-indexed data structure that contains a collection of values, called elements. The elements can be any data type, including strings, integers, hashes, other arrays, and other Ruby objects. …
Almost a year ago now, with Kelley’s blessing, I signed up for Flatiron School and decided to dedicate myself full-time to learning how to program. Last week I passed my final assessment! It feels good. I’ve spent the last year almost exclusively in front of the computer, nose down in books, watching and listening to tutorials, yelling at my programs, and it’s a little hard to grasp that it’s coming to an end. I know a few of those things will continue, especially the frustration, but so too will that feeling of pride and relief when I squash a bug…
My final Flatiron School assignment was to build a React app. I think the idea is a good one and while I’ve met the requirements to pass my assessment the app is far from being finished.
Here are the requirements…
create-react-app
generator to start your project.react-router
and proper RESTful routingFull Stack Software Engineer