Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
boiled down solution in Creative category for [old] Broken Clock by vincent.tscherter
"use strict";
function brokenClock(s, w, e) {
return [s, w] = [s,w].map (x => ( x=x.split(':'), 3600*x[0] + 60*x[1] + +x[2]) ),
e = e.split(' at ').map(x => x.split(' ')).map(y => (y[1][0]=='h'?3600:y[1][0]=='m'?60:1)*y[0]),
s = (w-s) * e[1] / (e[0] + e[1]) + s,
[s/3600, (s/60)%60, s%60].map(x => ("0"+(x|0)).slice(-2)).join(":")
}
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!");
}
Dec. 4, 2016
Comments: