Create a gist now

Instantly share code, notes, and snippets.

@djyugg /poh05_2.js
Last active Aug 29, 2015

What would you like to do?
var readline = require('readline').createInterface(process.stdin, process.stdout);
var inputs = [];
var ONE_WEEK_DAYS = 7;
readline.on('line', function (line) {
inputs.push(+line);
});
var createWeekInput = function (inputs) {
var result = [];
for (var i = 0; i < ONE_WEEK_DAYS; i++) {
result.push(+inputs.splice(0, 1));
}
return result;
};
var createWeeksInput = function (weeks, inputs) {
var result = [];
for (var i = 0; i < weeks; i++) {
result.push(createWeekInput(inputs));
}
return result;
};
readline.on('close', function () {
readline.close();
process.stdin.destroy();
var days = inputs.splice(0, 1);
var weeks = days / ONE_WEEK_DAYS;
var weeksInput = createWeeksInput(weeks, inputs);
var results = weeksInput.reduce(function (week1, week2) {
return week1.map(function (day, index) {
return day + week2[index];
});
});
results.forEach(function(result){
console.log(result);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment