This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function tabToggle (e) { | |
if (window.prevType !== e.type) { | |
switch (e.type) { | |
case 'blur': | |
// tab blur handler | |
break; | |
case 'focus': | |
// tab focus handler | |
break; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ONE_MINUTE = 60000; // 1 minute | |
/** | |
* Restricts callback to tail end of frequently recurring event listener. | |
* Examples include scroll, mousemove, keydown. | |
* @param {Function} fn function to debounce | |
* @param {Number} wait interval in milliseconds to wait between fn call | |
* @param {Boolean} immediate whether or not to call fn in front of wait interval | |
*/ | |
const debounce = (fn, wait, immediate) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Transform any array into an iterator. | |
* @param {array} arr array to be transformed | |
* @return methods object | |
*/ | |
var Iterator = function (arr) { | |
return { | |
index: -1, | |
hasNext: function () { return this.index < arr.length - 1; }, | |
hasPrevious: function () { return this.index > 0; }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Write a function that takes a DOM element and determines if it's an anchor tag | |
function isElementAnchorTag(el) { | |
return el.tagName.toLowerCase() === 'a'; // toLowerCase nice to have as not all browsers necessarily have the same case for tagNames | |
} | |
// Rewrite this function as method of the Element prototype | |
Element.prototype.isAnchorTag = function () { | |
return this.tagName.toLowerCase() === 'a'; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Verifies script has already been loaded on page. | |
* @param {function} test function returning true if script is on page | |
* @param {string} scriptURL URL of the script to load if it doesn't already exist on page | |
* @param {function} callback function to be executed once script has been verified | |
*/ | |
function verifyScript (test, scriptURL, callback) { | |
var selfDestructCallback = once(callback); | |
if (test()) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Given a string of only {, [, (, ), ], or } characters determine | |
* whether or not the parenthese are properly closed. | |
* @param {String} str | |
* value of parentheses string to validate | |
* @return {Boolean} | |
*/ | |
const isValidParens = (str) => { | |
const innerParens = /(\[\]|{}|\(\))/g; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Extend funtion to curried instance. | |
* @param {Function} fn | |
* function to be curried | |
* @return {Function} curried function | |
*/ | |
const curry = (fn, ...args) => { | |
return (...nArgs) => fn.apply(this, [...args, ...nArgs]) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Extends indexOf method to array-like objects. | |
* @param {Object} pseudoArray | |
* array-like object | |
* @param {Object} target | |
* target to test existance of in pseudoArray | |
* @return {Number} index of target | |
*/ | |
const indexOf = (pseudoArray, target) => { | |
return Array.prototype.indexOf.call(pseudoArray, target) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Caches results of executed functions. | |
* @param {function} fn function to cache | |
* @return {function} | |
*/ | |
function cacheFn (fn) { | |
var cache = {}; | |
return function () { | |
var argsStr = JSON.stringify(arguments); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Returns array containing nodes starting | |
* with root and traversing down to node. | |
* @param {node} node node to trace to root | |
* @return {array} | |
*/ | |
function pathToNode (node) { | |
var path = [node]; | |
var curr = node; |
OlderNewer