Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Clear&Readable solution in Clear category for [old] Call to Home by SaintDron
"use strict";
function totalCost(calls) {
let obj = {},
cost = 0;
for (let v of calls) {
var [day, _, duration] = v.split(' ');
obj[day] = Math.ceil(duration / 60) + (obj[day] || 0);
}
for (let key in obj) {
cost += (obj[key] > 100) ? 2 * obj[key] - 100 : obj[key];
}
return cost;
}
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 12, 2018