Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
3rd & final solution in Clear category for [old] Morse Clock by vincent.tscherter
"use strict";
function morseClock(a) {
var b = ".......-..-...--.-...-.-.--..----...-..-", c = "24-34-34";
return a // 00:1:02
.split(":") // ['00', '1', '02']
.map(a => ("0" + a).substr(-2)) // ['00', '01', '02']
.join(":").split("") // ['0', '0', ':', '0', '1', ':', '0', '2']
.map((a, d) => b.substr(4 * (+a + 1) - c[d], c[d]) || ":")
// ['..', '....', ':', ...
.join(" ");
}
var assert = require('assert');
if (!global.is_checking) {
assert.equal(morseClock("10:37:49"), ".- .... : .-- .--- : -.. -..-", "1st");
assert.equal(morseClock("21:34:56"), "-. ...- : .-- .-.. : -.- .--.", "2nd");
assert.equal(morseClock("00:1:02"), ".. .... : ... ...- : ... ..-.", "3rd");
assert.equal(morseClock("23:59:59"), "-. ..-- : -.- -..- : -.- -..-", "4th");
console.log("Coding complete? Click 'Check' to review your tests and earn cool rewards!");
}
Nov. 17, 2016
Comments: