The “depends” Amazon JavaScript code challenge

Phone displaying Amazon logo
Phone displaying Amazon logo
Photo by Christian Wiediger on Unsplash.

I recently went through my old dev projects and came across a JavaScript code challenge I did for Amazon. I had about half an hour to do it, and while I couldn’t complete it within that time frame back then, I decided to give it another try.

The challenge required a function that takes an array of task objects, and based on the depends property in each object, evaluates each task. Below is the original array:


A comparison of the two libraries for capturing React components as images

Charts on a laptop screen
Charts on a laptop screen
Photo by Luke Chesser on Unsplash.

I recently wrote an article about capturing React components as images and shared it on Reddit. One redditor commented on it, saying that while the library is robust, they used another one that they thought performed a bit better:

“A similar library that I ultimately ended up using was html-to-image. Much much faster and not only converts components to canvas but directly to png/blob/svg.”

We use html2canvas in another part of our application where we need to download multiple visualizations as separate images, zip them, and then download them. It works fine, but I have to say the performance can…


Quick and easy randomization

Dice
Dice
Photo by Edge2Edge Media on Unsplash.

There was a recent feature request at work that called for picking a random number to represent an index for an array of objects. We needed this logic to create a new, smaller collection of randomly selected items from the original array.

In this article, I’ll talk about how to use Math.random() to generate a random number between two numbers.

“The Math.random() function returns a floating-point, pseudo-random number in the range 0 to less than 1 (inclusive of 0, but not 1) with approximately uniform distribution over that range — which you can then scale to your desired range.” …


One sort function, two sort orders

I was recently working on a way to sort an array of objects alphabetically based on two columns. This means that both levels of alphabetical sorting should be maintained. See the example below.

var fruits = [
{colA: 'apple', colB: 'red delicious'},
{colA: 'pear', colB: 'red anjou'},
{colA: 'orange', colB: 'navel'},
{colA: 'orange', colB: 'blood'},
{colA: 'pear', colB: 'green anjou'},
{colA: 'apple', colB: 'granny smith'},
{colA: 'orange', colB: 'clementine'}
]
[
{colA: "apple", colB: "granny smith"},
{colA: "apple", colB: "red delicious"},
{colA: "orange"…


Just because you got an image in a certain color doesn’t mean it has to stay that way

Ladybug on a leaf
Ladybug on a leaf
Original photo (no BW) by Alexandre Debiève on Unsplash.

Imagine you receive a specific image from the product team that is meant to act as an icon for a button. The button has a white background, black border, black text, and the image itself is darker.


In Less Than Two Minutes

Photo by Christina @ wocintechchat.com on Unsplash

In this post, I will show you how to host your local web app as if it were deployed to a real, secure, domain. At the end is a quick video tutorial showing you that it takes less than 1 minute and 30 seconds to do this.

Below is the URL that I used in my browser to access my local file.

file:///User/matt/Development/my_app

First, I ran python -m SimpleHTTPServer while still in my project directory…


Holy sh*t you made it! Now what?

Photo by Lagos Techie on Unsplash

It’s been almost four years since I started Flatiron School’s Software Engineering Immersive program. Here’s what I’ve done since then I’ve had two jobs and am coming up on my third. my path thus far has not been a straight one.

I turned a two month contract as a web developer for a real estate company into a full-time role which was, technically, two full-time roles (Web Developer and IT Director) for the price of one…yay -_-. Was let go about 9 months later. …


A coding challenge to clear up 3 regular expression concepts

White frame
White frame
Photo by Clark Van Der Beken on Unsplash.

I recently came across an interesting code challenge that consisted of a few questions. The first question can be seen below:

“We love word clouds! Given the following text, print a list of all the words used and the number of times they appear. Please ignore punctuation and other uninteresting characters. Words should not be case-sensitive.”

We can break this challenge down into a few parts.

1. Remove All Punctuation and “Uninteresting” Characters

We can accomplish this by implementing a quick regular expression:

text.replace(/[^A-Za-z]+/g, " ")


Photo by Jon Tyson on Unsplash

Until February of this year I had been living at home with my mom. Despite having decent savings and enough monthly income to afford rent, I was compelled to stay at home.Why?

Money, duh


Using html2canvas

Photo by Carlos Muza on Unsplash

I was recently tasked with implementing logic that captures react components with their data visualizations on the web page and exports it as an image. Other data visualization libraries (such as Highcharts) allow for graphs to be exported as an image. However, we needed one to export multiple graphs and tables on a page at once.

This is where html2canvas comes in handy.

This package generates a “screenshot” by reading DOM elements, their styles, and then generating a canvas image from that data. It operates purely on the client side so you don’t have to worry about any requests/server support.

Matthew Croak

Code 📲💻 Wellness 🧘🏻‍♂️😌

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