Almost there, but this blows up of the len is smaller than the length of the string without padding. A small modification solves it ((len-sbl>0)):
var len = 6;
var sb = parseInt(1023).toString(2);
var sbl = sb.length;
var sbFixedLenStart = ('0').repeat((len-sbl>0)?(len-sbl):0) + sb;
var sbFixedLenEnd = sb + ('0').repeat((len-sbl>0)?(len-sbl):0);
Altho might need some tweaks to better fit Espruino's constraints...
© Espruino, powered by microcosm.
Report a problem