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 makeWorker(fn, args, callback) { | |
| var fnString = 'self.addEventListener("message", function (e) {self.postMessage((' + fn.toString() + ').apply(this, e.data))});', | |
| blob = new Blob([fnString], { type: 'text/javascript' }), | |
| url = URL.createObjectURL(blob), | |
| worker = new Worker(url); | |
| worker.postMessage(args); | |
| worker.addEventListener('message', function (e) { | |
| URL.revokeObjectURL(url); | |
| callback(e.data); |
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 hasIndex(array, index) { | |
| return array.splice(index, 1).reduce(function () { | |
| return true; | |
| }, false); | |
| } | |
| var array = []; | |
| hasIndex(array, 0); // => false | |
| array[0] = 1; |
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
| var bacon = (function () { | |
| var bacon = {}, | |
| defaultBase = 2; | |
| function getEncodedWidth(alphabet, base) { | |
| var width = 1 + Math.floor(Math.log(alphabet.length) / Math.log(base)); | |
| return width; | |
| } |
OlderNewer