Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for [old] Morse Clock by Sim0000
"use strict";
function bin(x, n){
c = ['.', '-']
r = []
for(i = 0; i < n; i++){
r.unshift(c[x & 1])
x >>= 1
}
return r.join('')
}
function morseClock(data) {
result = []
for(t of data.split(":")){
n = t | 0
result.push(bin(Math.floor(n / 10), 3))
result.push(bin(n % 10, 4))
result.push(':')
}
return result.join(" ").slice(1, -2)
}
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!");
}
July 7, 2016
Comments: