Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Rewritten for typescript solution in Clear category for Call to Home by Sim0000
import assert from "assert";
function totalCost(calls: string[]): number {
const database: {[day: string]: number} = {};
for(const call of calls){
const [day, time, duration] = call.split(' ');
database[day] = (database[day] ?? 0) + Math.ceil(Number(duration) / 60);
}
let total = 0;
for(const day in database){
const duration = database[day];
total += duration < 100 ? duration : 2 * duration - 100;
}
return total;
}
// memo. ?? is Nullish coalescing operator.
console.log('Example:');
console.log(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']));
// These "asserts" are used for self-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);
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);
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);
console.log("Coding complete? Click 'Check' to earn cool rewards!");
Sept. 6, 2020