• + 0 comments

    JS

    const l = s.length;
        const words = Math.ceil(Math.sqrt(l));
        const letters = Math.floor(Math.sqrt(l));
        const d = Number.isInteger(Math.sqrt(l)) ? 0 : 1;
        let r = '';
        
        for(let i =0; i<words; i++) {
            for(let j = i; j < l; j += letters + d) {
                r += s[j];
            }
            r += ' '; // 1 space
        }
        
        return r;