Elliot Sachs

Javascript, Economics, and Coffee

How To Migrate Your Ghost Blog To Zeit's Now
javascript programming js now zeit ghost zeit.world npm node

How To Migrate Your Ghost Blog To Zeit's Now

How to move your Ghost site from any hosting company to Zeit's Now service

Elliot Sachs
Elliot Sachs
5 min read
The Comma Operator in JavaScript
javascript programming basics comma

The Comma Operator in JavaScript

The comma operator takes two expressions, evaluates both and then returns the evaluation of the right expression. For example: const returnLeft = (x, y) => (y, x) returnLeft(3, 5) // 3 It's important to keep in mind that both expressions will be evaluated, meaning that you have to be aware of the possible side-effects of the first expression passed. For example: const log = (y) => console.log(`The value of y is ${y}`) let y = 1 returnLeft(y, log(y)) // The value of y is 1 // 1 Image Credi

Elliot Sachs
Elliot Sachs
1 min read
How To Get Rid Of Duplicate Objects In An Array
array javascript programming js object duplicate unique set es6 data structures

How To Get Rid Of Duplicate Objects In An Array

There might be a better way to do this, but I found it to be a pretty straightforward method. If you have an array of objects where some objects are duplicates, you can create a Set based on the property you want to use as a filter and then you can use the filter method over the original array, to only return the object if the property in question is still in the Set. If there's a match, you want to make sure to remove that property from the Set so the duplicated Object doesn't match with anyth

Elliot Sachs
Elliot Sachs
2 min read
How To Create A Singly Linked List In JavaScript
javascript algorithm data structures ECMAScript programming js computer science

How To Create A Singly Linked List In JavaScript

Linked Lists are relatively common and simple data structures that allow us to 'link'/chain data together. Linked Lists are useful for insertion/deletion (time complexity of O(1)), but are unfortunately not incredibly efficient when it comes to access and search (time complexity of O(n)). The core idea behind a linked list is that you have nodes that contain two pieces of information: * The data itself * A pointer towards the next piece of data The pointer is what chains the pieces of data

Elliot Sachs
Elliot Sachs
7 min read
List of Falsy Values in JavaScript & ToBoolean Algorithm
javascript algorithm toboolean boolean falsy truthy ECMAScript

List of Falsy Values in JavaScript & ToBoolean Algorithm

Here's a no frills post about the falsy values in JS. In case you didn't know, JavaScript considers some values as truthy and other as falsy. Most are deemed truthy so it's a lot easier to simply remember the falsy ones. You can see the truthy vs falsy evaluation in action when using an if statement. The statement takes in an expression and coerces it to a boolean value using the ToBoolean algorithm. The result is predictable and outlined in the table provided by the ECMAScript spec. Here it is

Elliot Sachs
Elliot Sachs
2 min read
Find duplicate integer in time O(n logn) and space O(n)
javascript programming algorithm snippet

Find duplicate integer in time O(n logn) and space O(n)

Here's how you can find a duplicate integer in a list of integers (read array) in space O(n) and time O(nlogn). This will only return the first duplicate integer in the array. Note: This only applies for a list of integers 1..n. This won't work otherwise. function findDuplicate(arr) { var floor = 1 var ceiling = arr.length - 1 while (floor < ceiling) { var midpoint = Math.floor(floor + ((ceiling - floor) / 2)) var lowerRangeFloor = floor var lowerRangeCeiling = midpoint

Elliot Sachs
Elliot Sachs
2 min read