How to create a null-filled array without [], comma, or the word “Array”

lionelrowe

lionel-rowe

Posted on January 5, 2022

How to create a null-filled array without [], comma, or the word “Array”
const praiseBeToCthulhu = (len) => {
    const obj = { a: '"' }
    obj.b = ''

    const codepoints = JSON.stringify(obj).split('')
        .map(ch => ch.codePointAt())

    const grab = (n) => codepoints.slice(n).shift()

    const x = grab(6)
    const y = grab(9)

    let s = String.fromCharCode(x - 1)

    for (let i = 0; i < len; ++i) {
        s += Object.getPrototypeOf(
            Object.getPrototypeOf(
                Object.getPrototypeOf(
                    Object
                )
            )
        )
        s += String.fromCharCode(y)
    }

    if (s.length > 1) {
        const z = s.split('')
        z.pop()

        s = z.join('')
    }

    s += String.fromCharCode(x + 1)

    return JSON.parse(s)
}
Enter fullscreen mode Exit fullscreen mode

OK, there are definitely more concise ways, but hey, maybe you're getting paid by the number of lines of code you write.

Thank-you for coming to my TED talk. 🙇‍♀️

💖 💪 🙅 🚩
lionelrowe
lionel-rowe

Posted on January 5, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related