Created
February 12, 2015 03:04
-
-
Save ajnadel/0b7dfcc655180bbaad6b to your computer and use it in GitHub Desktop.
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
{ | |
"name": "data-vis-intro", | |
"version": "1.0.0", | |
"description": "", | |
"main": "server.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1", | |
"start": "6to5-node server.js" | |
}, | |
"author": "", | |
"license": "MIT", | |
"dependencies": { | |
"express": "^4.11.2" | |
} | |
} |
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 dice = function(){ | |
return [Math.ceil(Math.random()*6), | |
Math.ceil(Math.random()*6)]; | |
}; | |
var add = function(x,y){ return x+y; }; | |
exports.diceSum = function(numberOfRolls){ | |
if (!numberOfRolls || numberOfRolls <= 0){ return false; } | |
var rollList = []; | |
while (numberOfRolls-- > 0){ | |
rollList.push(add.apply( null, dice() )); | |
} | |
return rollList; | |
}; | |
exports.diceSumMap = function(numberOfRolls){ | |
if (!numberOfRolls || numberOfRolls <= 0){ return false; } | |
var rollList = []; | |
while (numberOfRolls-- > 0){ | |
rollList.push( dice() ); | |
} | |
return rollList.map(function(roll){ | |
return roll[0] + roll[1]; | |
}).reduce(add); | |
}; | |
exports.diceSumMetaReduce = function(numberOfRolls){ | |
if (!numberOfRolls || numberOfRolls <= 0){ return false; } | |
var rollList = []; | |
while (numberOfRolls-- > 0){ | |
rollList.push( dice() ); | |
} | |
return rollList.map(function(roll){ | |
return roll.reduce(add); | |
}); | |
// .reduce(add); | |
}; |
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
/* jshint esnext: true */ | |
const express = require('express'); | |
const random = require('./random'); | |
var server = express(); | |
var port = process.env.PORT || 3726; | |
server.get('/', function(req, res){ | |
res.json(random.diceSum(6)); | |
}); | |
server.listen(port, function(){ | |
console.log(`serv-ed on ${ port }`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment