Playing around with the Hacker News API and noticed that it’s returning hundreds of story IDs when queried. It’s not ideal and can take longer to resolve. Since the Hacker News API is handled by Firebase we can use the limitToFirst or limitToLast query params to only return a set number of the first or last stories. Here’s what the top stories query would look like to return the first 10:| www.elliotsachs.com
I recently moved my site from Digital Ocean to Now and wanted to share some of the steps I took. The process isn’t overly complicated but I ended up making a few mistakes that made the process a bit harder than I thought it would be. This assumes the following: You already have the now-cli installed You have node and npm installed You are familiar with using CLI tools Your domain is managed by Zeit.| www.elliotsachs.com
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| www.elliotsachs.com
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; var upperRangeF...| www.elliotsachs.com
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.| www.elliotsachs.com
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 to...| www.elliotsachs.com
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.| www.elliotsachs.com
Took too long to fix this one. To open links in new tabs using Hugo’s Goldmark renderer, do the following: Create this file layouts/_default/_markup/render-link.html Add this in the file: {{ .Text }} And you’re done.| www.elliotsachs.com