Created
October 8, 2014 23:23
Coderwall article: https://coderwall.com/p/ttbjjq
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
#!/usr/bin/env node | |
function iNeedAnswers() { | |
var args = Array.prototype.slice.call(arguments), | |
answerCount = 0, | |
answers; | |
if (args.length < 1) { sampleRate = 1000; } | |
else if (parseInt(args[0], 10) != args[0]) { sampleRate = 1000; } | |
else { sampleRate = parseInt(args.shift(), 10); } | |
if (args.length < 2) { | |
args = ["Yes", "No"]; | |
} | |
answers = args.reduce(function(carry, answer) { | |
carry[answer] = 0; | |
return carry; | |
}, {}); | |
answerCount = args.length; | |
// Build an array with 1000 zeros | |
return Array.apply(null, new Array(sampleRate)) | |
.map(Number.prototype.valueOf, 0) | |
.map(function() { | |
// Fill up with zeros and ones | |
// based on random numbers (odd or even) | |
return Math.round(Math.random()*100000) % answerCount; | |
}) | |
.reduce( | |
function(carry, i) { | |
carry[args[i]]++; | |
return carry; | |
}, | |
answers | |
); | |
} | |
console.log(iNeedAnswers.apply(this, process.argv.slice(2))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment