Skip to content

Instantly share code, notes, and snippets.

View danielcaldas's full-sized avatar
👋

Daniel Caldas danielcaldas

👋
View GitHub Profile
@danielcaldas
danielcaldas / decorateAddEventListener.js
Last active September 16, 2019 21:57
decorateAddEventListener.js
/**
* This is a DOM utility function that allows you to decorate a specific event handler
* for a specific event type of a DOM element with some additional behavior
* (e.g. for each click on a given button I want to log something before the actual click handler is executed).
* @param {Object} targetElement the target dom element whose addEventListener we want to decorate.
* @param {string} targetEventType the target event type whose event handler we want to decorate.
* @param {Function} decorator a function that returns the new event handler for the targetEventType.
* This returned function will most likely contain additional behavior.
* NOTE: make sure that your decorator function calls the actual event handler
* at the end, otherwise you will override the original behavior designed for that event
@danielcaldas
danielcaldas / cloudSettings
Last active April 12, 2021 03:30
Visual Studio Code Settings Sync Gist
{"lastUpload":"2021-04-12T03:30:34.496Z","extensionVersion":"v3.4.3"}
/**
* Drops array elements while specified condition is met
* @param {Array.<T>} array
* @param {Function} cb condition to drop elements
* @returns {Array.<T>} returns array tail of resulting operation
*/
function dropWhile(array, cb) {
const n = array.length;
let i = 0;