Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for [old] Call to Home by mortonfox
"use strict";
function totalCost(calls){
var daterec = {};
for (var call of calls) {
var cols = call.split(' ');
var date = cols[0];
var mins = Math.ceil(+cols[2] / 60);
if (!(date in daterec)) daterec[date] = 0;
daterec[date] += mins;
}
return Object.values(daterec).reduce((sum, mins) => sum + Math.min(100, mins) + 2 * Math.max(0, mins - 100), 0);
}
var assert = require('assert');
if (!global.is_checking) {
assert.equal(totalCost(["2014-01-01 01:12:13 181",
"2014-01-02 20:11:10 600",
"2014-01-03 01:12:13 6009",
"2014-01-03 12:13:55 200"]), 124, "Base example");
assert.equal(totalCost(["2014-02-05 01:00:00 1",
"2014-02-05 02:00:00 1",
"2014-02-05 03:00:00 1",
"2014-02-05 04:00:00 1"]), 4, "Short calls but money...");
assert.equal(totalCost(["2014-02-05 01:00:00 60",
"2014-02-05 02:00:00 60",
"2014-02-05 03:00:00 60",
"2014-02-05 04:00:00 6000"]), 106, "Precise calls");
console.log("Coding complete? Click 'Check' to review your tests and earn cool rewards!");
}
March 24, 2017