Menu

Performance Differences for Inserting Into an Array

I was bored and curious and decided to compare the performance among different ways of inserting an element into the middle of an array. I tried three methods: Using Array.splice() Using Array.slice() and Array.concat() Using the ES6 rest operator The winner was using the combination of Array.…

ES6 Promises: Best Practices

After using more and more promises lately, I've gathered a handful of good and bad design patterns for promises. I'm going to list out some examples of how promises are typically used and demonstrate anti-patterns and how to clean them up. Like everyone, I've been guilty to some of these…

String Compression and Concatenation Performance

Here is a whiteboarding problem that may come up in interviews. You are given a string. Implement a function to perform basic string compression using the counts of repeated characters. For example, the string aabcccccaaa would become a2blc5a3. If the "compressed" string would not become smaller than the original string,…

Tree Traversal

BFS vs. DFS When you need to search or traverse a graph or tree-like structure, there are two common algorithms: breadth-first search and depth-first search. Which algorithm to use really depends on the structure of the tree and the location of the items you need to find. Here are some…

Preview of ES6

Who's excited for ES6? Hold on to your socks. Here is a sneak peek of what's to come in ECMAScript 6. let and const let can be used to declare variables just like var, but let has no hoisting, it has lexical scoping within () and {} blocks, and you cannot redeclare…