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
/* | |
[DESAFIO / LANGUAGE WAR] Implemente um programa na sua linguagem favorita onde o usuário digita um número x, e o programa calcula o somatório dos x primeiros números pares da sequência fibonacci, e imprime a soma dos algarismos desse número. | |
Por exemplo, quando x = 5, a resposta é 17, pois: | |
1. A sequência fibonacci é 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233,... | |
2. Os 5 primeiros números pares são 0, 2, 8 e 34, 144. | |
3. O somatório disso é 188. | |
4. Somando os algarismos, 1+8+8 = 17 |
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 fun(yes) { | |
return yes? { foo: 'hello' | |
, bar: false | |
, quux: 10 | |
} | |
: /* otherwise */ { foo: 'hey' | |
, bar: true | |
, quux: 20 | |
} |
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
(data "title" "My Story") | |
(data "author" "Mortchek") | |
(start-page "foo") | |
(page "foo" | |
(text "You are in a place.\n") | |
(choice (go "bar") "Do a thing!\n") | |
(choice (go "baz") "Do a different thing!\n") | |
(choice (give "sword") "Pick up a sword!\n") | |
(choice (give "shield") "Pick up a shield!\n") |
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 last(xs){ return xs[xs.length - 1] } | |
function split(predicate, xs) { | |
return reduce( xs | |
, function(rv, x, i) { return predicate(x, i)? rv.concat([[x]]) | |
: /* otherwise */ (last(rv).push(x), rv) } | |
, [[ ]]) } | |
function splitEvery(n, xs) { return split(function(x, i){ return i > 0 && i % n == 0 }, xs) } |
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 p1 = getMetadata(key, EPID) | |
var p2 = getStreams(key, EPID) | |
var p3 = Promise.make().waitFor(p1, p2).bind(p1, p2) | |
.ok( function(metadata, streams) { doSomething(metadata.value, streams.value) }) | |
.failed(function(metadata, streams) { doStomethingElse(metadata.value, streams.value) }) | |
.done( function(metadata, streams) { next() }) |
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
Can2D.prototype.C_Error = function(msg, fileName, lineNumber){ | |
var e = Error.call(this, msg, filename, lineNumber) | |
e.name = 'C_Error' | |
return e | |
} | |
Can2D.prototype.C_Error.prototype = Object.create(Error.prototype) |
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
Can2D.prototype.C_Error = function(msg, fileName, lineNumber){ | |
return Error("Can2D: "+msg, fileName,lineNumber); | |
} | |
Can2D.prototype.CError.prototype = Error.prototype; |
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
/** | |
* Applies a set of named arguments to a `func`. | |
* | |
* Example: var f = function(x, y, z) { return x * (y - z); }; | |
* namedApply(f, {x: 1, y: 2, z: 3}); | |
* | |
* @param f {Function} A function to invoke. | |
* @param args {Object} A collection of named arguments. | |
* @return {Function} A new function with partially applied named arguments. | |
*/ |
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
void function(root){ | |
var Point = boo.Base.derive({ | |
init: | |
function(x, y) { | |
this.x = x | |
this.y = y | |
return this } | |
, fromPoint: |
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 pubsub = { | |
// A map of event names to the listeners attached to it. | |
// :: { "String" -> [Function] } | |
events: { } | |
// Notifies all the listeners of an event | |
// :: String, a... -> Undefined | |
, pub: function(event) { | |
var events = this.events[event] || [] | |
var args = arguments |