DEV Community

lionel-rowe
lionel-rowe

Posted on

2 2

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. 🙇‍♀️

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more