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
| // Imperetive: | |
| function factorial(n) { | |
| var result = 1; | |
| for (var i = 1; i <= n; i++) { | |
| result *= i | |
| } | |
| return result; | |
| } | |
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
| // curry function and accepts lists of parameters | |
| function curry(fn) { | |
| // begin with an empty array of collected arguments | |
| var partialArgs = []; | |
| var f = function() { | |
| // append all passed in arguments to the arguments collection | |
| Array.prototype.push.apply(partialArgs, arguments); | |
| // if we have matched or exceeded the argument length of the containing function | |
| // call the function with the required length (extra parameters are ignored) |
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
| Practicing underscore foo... | |
| checkErrors: function(attrs) { | |
| var errors = []; | |
| _.each(this.basicValidationFields, function(key) { | |
| errors.push(this.validatePresence(key, attrs[key])); | |
| }.bind(this)); | |
| errors = _.compact(errors); | |
| if (errors.length) return errors; |
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 CANVAS_CTX = canvas.getContext('2d'); | |
| var DRAW_PIXEL_ID = CANVAS_CTX.createImageData(1,1); | |
| var DRAW_PIXEL_DATA = DRAW_PIXEL_ID.data; | |
| function drawPixel(ctx, x, y, r, g, b, a) { | |
| DRAW_PIXEL_DATA[0] = r; | |
| DRAW_PIXEL_DATA[1] = g; | |
| DRAW_PIXEL_DATA[2] = b; | |
| DRAW_PIXEL_DATA[3] = a; | |
| ctx.putImageData( DRAW_PIXEL_ID, x, y ); |
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 mandelbrotRank (x, y, timeout) { | |
| var i = 0, | |
| zx = x, | |
| zy = y; | |
| while (zx*zx + zy*zy < 4 && i < timeout){ | |
| zx = zx*zx - zy*zy + x + offx; | |
| zy = 2*zx*zy + y + offy; | |
| i += 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
| <html> | |
| <head> | |
| <script type="text/javascript" src="../lib/jqueryui/js/jquery-1.7.1.min.js"></script> | |
| <script type="text/javascript" src="../lib/drawer.js"></script> | |
| </head> | |
| <body> | |
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 animate(fn) { | |
| var halted = false; | |
| var f = function() { | |
| fn(); | |
| if (!halted) requestAnimationFrame(f); | |
| } | |
| f(); |
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 point(x, y) { | |
| return { | |
| x: x, y: y, | |
| shift: function(x, y) { | |
| return _.extend({}, this, { | |
| x: this.x + x, | |
| y: this.y + y | |
| }) | |
| } |
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 add(a, b, c) { | |
| return a + b + c; | |
| } | |
| console.log( add.apply(null, [1, 2, 3]) ); | |
| // 6 | |
| console.log( add.call(null, 2, 3, 4) ); | |
| // 9 |
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 spreadable(f) { | |
| return function() { | |
| return f.apply(null, _.flattenDeep(arguments)) | |
| }; | |
| } | |
| var a = spreadable(function (a, b, c, d, e, f, g, h) { | |
| return [a, b, c, d, e, f, g, h]; | |
| }); |
OlderNewer