This file contains 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 fibo = (function () { | |
var memo = {}; | |
function fi(n) { | |
if (n < 0) { return -1 } else { | |
var value = (n in memo) ? memo[n] : (!n || n === 1) ? 1 : fi(n - 1) + fi(n - 2); | |
memo[n] = value; | |
return value; | |
} | |
} | |
return fi; |
This file contains 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
// add some basic error handling | |
var q = require("q"); | |
var fs = require("fs"); | |
function qread(file) { | |
var _q = q.defer(); | |
fs.readFile(file, "utf-8", function (err, data) { | |
if (err) { _q.reject(new Error(err)) | |
} else { _q.resolve(data); } | |
}); | |
return _q.promise; |
This file contains 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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |