An array of objects is a developer’s bread and butter.

You got an array, which means you can make use of all the great array methods like .map() , .filter() , .reduce() (and all the rest), making this data structure eminently loopable, and very easy to safely transform.

…And you got a bunch of individual objects that have predictable structure, and key/values that make it very easy to reference the exact data you want to work with.

The only thing that could make this perfect combination better, is perhaps a snappier name. …


The title says it all. Let’s get straight into this.

1. Create a dummy array to duplicate components

Say you want to create a loading state or empty state where you’ll duplicate a number of components…

Sure, you could just copy/paste the component several times and be done with it. But code like this makes me feel like I suck at programming... 😝

<DummyMessageBlock />
<DummyMessageBlock />
<DummyMessageBlock />

Instead, you can create a dummy array, and return the component for each item you want to duplicate like this:

let DuplicatedBlocks = [...Array(5)].map((_, index) => {
return <DummyMessageBlock key={index} />
});
return DuplicatedBlocks;

[...Array(5)] initiates an empty array…


CSS has been with us since the before time, in the long, long ago…

According to wikipedia, CSS was introduced in 1996, just shortly after HTML and the World Wide Web made their grand entrance on the stage of history. — — Making CSS a 23 y/o language, and one of the oldest technologies of the web that is still with us to this day!

Regardless of whether you are writing vanilla CSS for styling a landing page, or using full-blown styled-components in a full-stack React application, there may be a question that lingers in the back of our minds…


Picture yourself standing in front of the white board. You have your coding problem, you’ve gone over the typical questions — inputs, outputs and edge cases. Are there negative numbers? Is the data sorted? What if the parameters are null? You have a solution in hand and you’re ready to begin pseudo-coding, and your interviewer asks, “What is the time complexity of that?”

There is a language unto itself when talking about Big O notation or the time and space complexity of an algorithm. We hear things like, “Oh that’s quadratic…”, “Can you do better than linear?”, and so on..


A running list of algorithm questions and answers that commonly appear in programming interviews.

Since the goal of this exercise is to practice logical skills necessary for a coding interview, I will avoid using most built-in JS methods, and will rely on for/while and for-in loops to iterate through data structures.

Also, for simplicity, I will assume that expected inputs will be correct so I don’t have to waste space doing error checking or validation. So if an array is the expected parameter, the input will not be an object, and so on.

Arrays

One of the most common data structures…


Part 2 of a series on algorithm solving techniques. Check out Part 1 if you missed it!

Use a “nested for-loop”

Nested for-loops, or a for-loop within a for-loop, are not so efficient. However, they give us an easy way to loop through data and perform actions. Perhaps the most famous example of a nested for-loop in action is the infamous ‘Bubble Sort’ algorithm:

function bubbleSort(array) {
for (var i = 0; i < array.length; i++) {
for(var j = 0; j < array.length; j++) {
if(array[i]<array[j]) {
// swap values
var temp = array[j];
array[j] = array[i];
array[i] = temp;
}
}
}


Foundational techniques that will come in handy when solving all sorts of different algorithm problems.

This is not an exhaustive list and I’m sure there are ways to improve upon them. So I look forward to feedback in the comments below.

When I first started solving algorithms, I didn’t know about these techniques and had to learn them the hard way. My hope is that this list will help those starting out or looking to improve their algorithm solving techniques by showing the stepping stones needed for building strong algorithm solving skills.

Creating a ‘counter’ variable

A ‘counter’ variable will allow you to store…

Elliott

I like learning languages and talking about web development.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store