A Collection of The Stuffs I've Done:

GeoTreasure

Rescuisine

Battle of Life

BrBa Quiz

Playlist App

Git Tutorial

Memory Game

A recent talk I gave:

Latest post from my blog:

Debounce with me bounce with me

Bounce with me So got a fun interview question today. Didn’t actually end up solving it, but felt like it was a cool question that I wanted to write about. Here it is:  “Write your own debounce function” Before I jump into the solution, if you’re unfamiliar with what debouncing is as a concept, it’s essentially a way to prevent the over-invocation of any given function (I totally made the word over-invocation up, but I think it works here).  For example, for a typeahead search, rather than making a call to get new search results upon every key stroke, debouncing is often used in order to limit the rate at which API calls are made to retrieve those results. E.g. if you type 5 letters in a matter of 2 seconds, we’d only call the API endpoint once when 2 seconds has passed from the last keystroke as opposed to five times. So back to the question. I was given this function definition and an example of its usage as the following: 

const debounce = (fn, delay) => {
};

const sayHi = () => {
    console.log('yo!');
};

const debouncedSayHi = debounce(sayHi, 100);
So what should debounce look like? At first glance, I knew in the back of my head this was going to involve a closure somehow… The first clue was the the return value of debounce was another function, which implies that a closure exists, whether there is state held outside of the function that gets used within the returned function or not. Before we get started it might help to know that whenever you call setTimeout(), a reference to that specific timeout is returned. You can later cancel that specific timeout using that object that was returned, i.e.
const timeout = setTimeout(someFunction, 100)
clearTimeout(timeout)
someFunction will never be invoked. So what did the solution end up looking like? Check this out:
Read more...