This file contains 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
var isBoolean = is('Boolean'), | |
isNumber = is('Number'), | |
isString = is('String'), | |
isObject = is('Object'), | |
isArray = is('Array'); | |
function is(type) { | |
var fastTypes = ['undefined', 'boolean', 'string', 'number', 'function', 'symbol']; | |
if (fastTypes.indexOf(type.toLowerCase()) >= 0) { | |
type = type.toLowerCase(); |
This file contains 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 partial (fn) { | |
var initialArgs = Array.prototype.slice.call(arguments, 1); | |
return function () { | |
var remainingArgs = Array.prototype.slice.call(arguments); | |
return fn.apply({}, initialArgs.concat(remainingArgs)); | |
} | |
} | |
function findIndex(arr, predicate) { | |
var i; |
This file contains 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 compact(a) { | |
return a.reduce(function(memo, x) { | |
return x ? memo.concat(x) : memo; | |
}, []); | |
} |
This file contains 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 flatten(a) { | |
return a.map(function(val) { | |
return (Array.isArray(val)) ? flatten(val) : val; | |
}); | |
} | |
//example usage | |
var arr = [1, 2, [3, 4], 5, [6, [7, [8]], 9], 10]; | |
var flat = flatten(arr); // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] |
This file contains 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 Queue = () => { | |
let array = []; | |
return { | |
push: (value) => array.push(value), | |
pull: () => array.shift(), | |
isEmpty: () => !array.length | |
}; | |
}; |
This file contains 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 copyObject = (source) => Object.assign({}, source); | |
const Stack = () => { | |
const array = []; | |
return { | |
push (value) { | |
array.push(value); | |
}, | |
pop () { |
This file contains 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
memo = function (fn) { | |
var cache = {}; | |
return function () { | |
var key = JSON.stringify(this, arguments); | |
return cache[key] || (cache[key] = fn.apply(this, arguments)); | |
} | |
} |
This file contains 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
// Kestrel | |
const K = ( x ) => ( y ) => x; | |
// Identity | |
const I = ( x ) => x; | |
// Vireo | |
const V = ( x ) => ( y ) => ( z ) => z( x )( z ); | |
// Thrush | |
const T = ( x ) => ( y ) => y( x ), x; | |
// Why | |
const Y = ( x ) => ( ( y ) => y( y ) )( ( y ) => ( x( ( z ) => y( y )( z ) ) ) ); |
This file contains 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
$._data( $(selector)[0], "events" ); |
This file contains 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 jquery with function to check if element exists | |
$.fn.exists = function(){ | |
return this.length > 0 ? this : false; | |
} | |
//usage | |
$('.matchme').exists(); //returns reference to element if exists otherwise false |