Digital Clock

Demonstrates Excel’s streaming and spill functionality (run with CALLSTREAM).

func clock
const col = [['','',''],['','*',''],['','',''],['','',''],['','*',''],['','','']];
const n = [
[['','*',''],['*','','*'],['*','','*'],['*','','*'],['*','','*'],['','*','']],
[['','*',''],['*','*',''],['','*',''],['','*',''],['','*',''],['*','*','*']],
[['','*',''],['*','','*'],['','','*'],['','*','*'],['*','',''],['*','*','*']],
[['*','*',''],['','','*'],['','*','*'],['','','*'],['','','*'],['*','*','']],
[['','','*'],['*','','*'],['*','','*'],['','*','*'],['','','*'],['','','*']],
[['','*','*'],['*','',''],['','*','*'],['','','*'],['*','','*'],['','*','']],
[['','*','*'],['*','',''],['*','*',''],['*','','*'],['*','','*'],['','*','*']],
[['*','*',''],['','','*'],['','*',''],['','*',''],['*','',''],['*','','']],
[['','*',''],['*','','*'],['','*',''],['*','','*'],['*','','*'],['','*','']],
[['','*',''],['*','','*'],['','*','*'],['','','*'],['*','','*'],['*','*','']]];
const numToA = (num) => [...num.toString().padStart(2, '0')].map(d => d * 1);
const toNum = (r, num) => numToA(num).reduce((s,e) => [...s, ...n[e][r], ''],[]);
const time = (hour, mins, secs) => [0,1,2,3,4,5].reduce((s,e) => [...s,
[...toNum(e,hour), ...col[e], ...toNum(e,mins), ...col[e], ...toNum(e,secs)]],[]);
const print = () => {
 const tm = new Date();
 invocation.setResult(time(tm.getHours(),tm.getMinutes(),tm.getSeconds()));
};
print();
const timer = setInterval(() => {
 print();
}, 1000);
invocation.onCanceled = () => clearTimeout(timer);


Copyright © 2020 Finnur Bragason.