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
| // haskell | |
| // sort [] = [] | |
| // sort (x:xs) = sort lte ++ [x] ++ sort gt | |
| // where lte = [a | a <- xs, a <= x] | |
| // gt = [a | a <- xs, a > x] | |
| const data = [4,5,8,9,1,2,3,9,1,5,1,9,5,3,3,3,8,9]; | |
| function sort(data) { | |
| if (_.isEmpty(data)) return []; |
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 [head, ...tail] = [1,2,3]; | |
| // head 1 | |
| // tail [2,3] |
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 _ = require('lodash'); | |
| function Point(x, y) { | |
| return {x, y}; | |
| }; | |
| const Color = { | |
| black: {r: 255, g: 255, b: 255, y: 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
| function compose(...fns) { | |
| return x => _.reduceRight(fns, (acc, f) => f(acc), x); | |
| } | |
| const square = x => x * x; | |
| const double = x => x + x; | |
| const squareDouble = compose(square, double); | |
| const test = compose(); // empty compose acts like identity |
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 d = { | |
| share: 5, | |
| promote: 6, | |
| engage: 11, | |
| discover: 1 | |
| } | |
| const total = _(d).values().sum(); | |
| const buckets = _(d) |
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 any() { | |
| return _.reduce(arguments, function(sum, n){ return sum || n; }, false); | |
| } | |
| function any() { | |
| return _.some(arguments); | |
| } | |
| function all() { | |
| return _.reduce(arguments, function(sum, n){ return sum && n; }, true); |
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 (timeout, x, y) { | |
| var i = 0, | |
| zx = x, | |
| zy = y; | |
| while (zx*zx + zy*zy < 4 && i < timeout){ | |
| var tx = zx*zx - zy*zy + x, | |
| ty = 2*zx*zy + y; | |
| zx = tx; |
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
| // haskell | |
| // sort [] = [] | |
| // sort (x:xs) = sort lte ++ [x] ++ sort gt | |
| // where lte = [a | a <- xs, a <= x] | |
| // gt = [a | a <- xs, a > x] | |
| var data = [4,5,8,9,1,2,3,9,1,5,1,9,5,3,3,3,8,9]; | |
| function sort(data) { | |
| if (data.length === 0) return []; |
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 circle = (function() { | |
| // all shapes should show by default at the center of the canvas | |
| var x = 10, | |
| y = 10, | |
| radius = 10; | |
| return { | |
| at: function(x, y) { | |
| this.x = x; | |
| 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
| // don't have to declare frame, purer | |
| function animate(fn) { | |
| function anim(frame) { | |
| fn(frame); | |
| requestAnimationFrame(_.partial(anim, frame + 1)); | |
| } | |
| requestAnimationFrame(_.partial(anim, 0)); | |
| } | |