I hereby claim:
- I am danielrw7 on github.
- I am danielrw (https://keybase.io/danielrw) on keybase.
- I have a public key ASAk-oo3HcNTfezT-rsWc1XfYNJPJb1Q4TU5e4OidsIr4wo
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
| RegExp.escape = function(text) { | |
| return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); | |
| } | |
| function searchScore(query, data) { | |
| var query = query.toString().replace(/\s+/g, " "); | |
| var queryRegEx = new RegExp(RegExp.escape(query), "g"); | |
| function uniqueArray(array) { | |
| var result = []; | |
| for(var i in array) { | |
| if (result.indexOf(array[i]) === -1) { |
| function pickWeighted(array) { | |
| var n = Math.random(), | |
| totalChances = 0, | |
| total = 0, | |
| result; | |
| array = array.map(function(row) { | |
| var min, max; | |
| var chance = typeof row == 'object' || typeof row == 'function' ? row.chance : 1; | |
| if (chance) { | |
| min = totalChances; |
| var object = { | |
| "value": 1, | |
| "anotherValue": 2, | |
| "nested": { | |
| "value": 3 | |
| } | |
| }; | |
| object.value | |
| // => 1 |
| function extend() { | |
| var result = arguments[0]; | |
| for(var i = 1; i < arguments.length; i++) { | |
| for(var key in arguments[i]) { | |
| result[key] = arguments[i][key]; | |
| } | |
| } | |
| return result; | |
| } |
| function toArray(array) { | |
| return Array.prototype.slice.call(array); | |
| } |
| function extend() { | |
| var result = arguments[0]; | |
| for(var i = 1; i < arguments.length; i++) { | |
| for(var key in arguments[i]) { | |
| result[key] = arguments[i][key]; | |
| } | |
| } | |
| return result; | |
| } |
| function typedArgument(type, value, defaultValue) { | |
| return (typeof value !== 'undefined' && typeof value !== 'null' && ((typeof type === 'function' && value.constructor === type) || (typeof type === 'string' && (!type || typeof value === type)))) ? value : defaultValue; | |
| } | |
| /** Example: **/ | |
| function add(a,b) { | |
| var a = typedArgument(Number, a, 0); | |
| var b = typedArgument('number', b, 0); | |
| return a + b; | |
| } |
| var variableArgs, | |
| slice = [].slice; | |
| variableArgs = function(callbacks) { | |
| var defaultKey; | |
| defaultKey = 'default'; | |
| return function() { | |
| var args, numArgs, ref; | |
| args = 1 <= arguments.length ? slice.call(arguments, 0) : []; | |
| numArgs = args.length || 0; |
| var MapObj = function(obj, mapFn) { | |
| var key, result, val; | |
| if (obj.length && obj.join) { | |
| return obj.map(mapFn); | |
| } | |
| result = {}; | |
| for (key in obj) { | |
| val = obj[key]; | |
| result[key] = mapFn(val, key); | |
| } |