# npm install git://gist.github.com/4033566.git
# require('minispec') in your project
require('./minispec')
# use expect.js for assertion (http://n37.co/5gpfa)
expect = require('expect.js')
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 Robot = function(robot){ | |
| robot.turnLeft(robot.angle % 90); | |
| }; | |
| Robot.prototype.onIdle = function(ev) { | |
| var robot = ev.robot; | |
| if (robot.parentId) { | |
| robot.ahead(1); | |
| robot.turnGunRight(1); | |
| } | |
| else { |
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
| web: node app.js |
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
| heroku apps:create [app-name] --remote [env name] | |
| than add --remote [env name] to execute command on env | |
| set the environment varible and addons | |
| ex: | |
| heroku config set XXX=OOO --remote [env name] | |
| heroku addons .... --remote [env name] |
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 singles = [ | |
| '', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', | |
| 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen' | |
| ]; | |
| var tenth = ['', 'ten', 'twenty', 'thirty', 'fourty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety']; | |
| var unit = ['', 'thousand', 'million', 'billion']; | |
| module.exports = function (n) { | |
| var result = []; | |
| var len = n.toString().length; |
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 singles = [ | |
| '', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', | |
| 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen' | |
| ]; | |
| var tenth = ['', 'ten', 'twenty', 'thirty', 'fourty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety']; | |
| var unit = ['', 'thousand', 'million', 'billion']; | |
| module.exports = function (n) { | |
| var result = []; | |
| var len = n.toString().length; |
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
| module.exports = function (seq) { | |
| var maxsum = 0; | |
| for (var i = 0; i < seq.length; i++) { | |
| var sum = 0; | |
| for (var j = i; j < seq.length; j++) { | |
| sum += seq[j]; | |
| if(sum > maxsum) { | |
| maxsum = sum; | |
| } | |
| }; |
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
| module.exports = function (seq) { | |
| var maxsum = -1000000000; | |
| var sum = 0; | |
| for (var i = 0; i < seq.length; i++) { | |
| sum += seq[i]; | |
| if(sum > maxsum) { | |
| maxsum = sum; | |
| } | |
| if (sum < 0) { | |
| sum = 0; |
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
| module.exports = function (book, word) { | |
| var words = book.replace(/.,/, ' ').toLowerCase().split(' '); | |
| var dict = {} | |
| words.forEach(function(w) { | |
| if (dict[w]) { | |
| dict[w] += 1; | |
| } else { | |
| dict[w] = 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 count2 = function(n) { | |
| if (n == 0) return 0; | |
| var power = 1; | |
| while (10 * power < n) power *= 10; | |
| var first = Math.floor(n / power); | |
| var remain = n % power; | |
| var n2s = 0; | |
| if (first > 2) { |