You are reading a single comment by @PaddeK and its replies. Click here to read the full conversation.
  • Okay here are the results in respect of RLE.

    First the two contenders:

    Unminified

    module.exports = {
        enc: string => {
            let map = (count, char) => (count > 1 ? count : '') + ('¾µÀÁÂÃÄÅÆÇ'[char] || char),
                counter = 0,
                last = '';
    
            return [].reduce.call(string, (result, char, index) => {
                if (last !== char) {
                    result += map(counter, last);
                    counter = 0;
                    last = char;
                }
    
                counter++;
    
                if (index >= string.length - 1) {
                    result += map(counter, last);
                }
    
                return result;
            }, '');
        },
        dec: string => {
            let map = char =>'0123456789'['¾µÀÁÂÃÄÅÆÇ'.indexOf(char­)] || char,
                count = '';
    
            return [].reduce.call(string, (result, char) => {
                if (!isNaN(parseInt(char))) {
                    count += char;
                    return result;
                } else {
                    result += count.length ? new Array(parseInt(count) + 1).join(map(char)) : map(char);
                    count = '';
                }
                return result;
            }, '');
        }
    };
    

    Minified

    module.exports=((a,b)=>({enc:t=>b.call(t­,(p,c,x)=>{return p.l!==c&&([p.r,p.c,p.l]=[p.r+p.f(p.c,p.l­),0,c]),p.c++,x>=t.length-1&&(p.r+=p.f(p­.c,p.l)),p},{l:'',r:'',c:0,f:(c,s)=>(c>1­?c:'')+(a[s]||s)}).r,dec:t=>b.call(t,(p,­c)=>{return[p.r,p.j]=[~~c==c?p.r:p.r+(p.­j?Array(+p.j+1).join(p.m(c)):p.m(c)),~~c­==c?p.j+c:''],p},{r:'',m:i=>'0123456789'­[a.indexOf(i)]||i,j:''}).r}))('¾µÀÁÂÃÄÅÆ­Ç',[].reduce)
    

    I minify by hand but i tested the code in the browser and nodejs and confirmed both versions work as expected. It is not a straight RLE implementation as you can see.. the purpose is to minify base64 strings, so there is some substitution going on.

    In regard to espruino the unminfied version is running fine. The minified version however behaves unexpected. The webIDE freezes.. reconnecting to the board does not work, even typing on the left side is not working. Restarting the webIDE has no effect. I have to reflash my espruino wifi to fix this.

    -- Edit --
    I tested the latest cutting edge build (1v94.130) with this

    let dec = t => t.replace(/(\d+)([^\d])/g, (m, r, c) => new Array(+r + 1).join(c)).replace(/[¾µÀÁÂÃÄÅÆÇ]/g, i => i.charCodeAt(0) % 10);
    

    I get the same behaviour as with my minified non regex version.

About

Avatar for PaddeK @PaddeK started