lukeed / obj-str

A tiny (96B) library for serializing Object values to Strings.
MIT License
247 stars 7 forks source link

obj-str build cls=[] via .push then => cls.join #14

Closed DarrenSem closed 1 year ago

DarrenSem commented 1 year ago

Instead of this:

export default function (obj) {
    var k, cls='';
    for (k in obj) {
        if (obj[k]) {
            cls && (cls += ' ');
            cls += k;
        }
    }
    return cls;
}

Use this more clear logic:

export default function (obj) {
    var k, cls=[];
    for (k in obj) {
        if (obj[k]) {
            cls.push(k);
        }
    }
    return cls.join(" ");
}
lukeed commented 1 year ago

No thanks. Clarity is the same (subjective) but the performance of direct string building (current) is significantly faster than array building + joining