Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Clear solution in Clear category for [old] Broken Clock by GazonkFoo
"use strict";
function brokenClock(startingTime, wrongTime, errorDescription){
var seconds = s => parseInt(s[0])*3600 + parseInt(s[1])*60 + parseInt(s[2]);
var time = s => [s/3600, (s/60)%60, s%60].map(s => ("0"+Math.floor(s)).slice(-2)).join(":");
var start = seconds(startingTime.split(":"));
var wrong = seconds(wrongTime.split(":"));
var error = errorDescription.split(" at ").map(s => s.split(" ")).map(s =>
(!s[1].indexOf("minute") ? 60 : !s[1].indexOf("hour") ? 3600 : 1) * s[0]
);
return time(((wrong-start) * error[1] / (error[0] + error[1])) + start);
}
var assert = require('assert');
if (!global.is_checking) {
assert.equal(brokenClock('00:00:00', '00:00:15', '+5 seconds at 10 seconds'), '00:00:10', "First example");
assert.equal(brokenClock('06:10:00', '06:10:15', '-5 seconds at 10 seconds'), '06:10:30', "Second example");
assert.equal(brokenClock('13:00:00', '14:01:00', '+1 second at 1 minute'), '14:00:00', "Third example");
assert.equal(brokenClock('01:05:05', '04:05:05', '-1 hour at 2 hours'), '07:05:05', "Fourth example");
assert.equal(brokenClock('00:00:00', '00:00:30', '+2 seconds at 6 seconds'), '00:00:22', "Fifth example");
console.log("Coding complete? Click 'Check' to review your tests and earn cool rewards!");
}
Sept. 29, 2016