• 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);

    MDN usually has polyfills or in this case, a link to polyfills: https://developer.mozilla.org/en-US/docs­/Web/JavaScript/Reference/Global_Objects­/String/padStart
    Altho might need some tweaks to better fit Espruino's constraints...


Avatar for AkosLukacs @AkosLukacs started