d3 / d3-dsv

A parser and formatter for delimiter-separated values, such as CSV and TSV.
https://d3js.org/d3-dsv
ISC License
437 stars 76 forks source link

`objectConverter` can work without `Function`. #94

Closed KaKi87 closed 2 years ago

KaKi87 commented 2 years ago

Hello,

The objectConverter function, if I understand it correctly, takes an array of keys, and returns a function, that takes an array of values, and returns an object.

I'm guessing preserving IE11 compatibility was the goal, so here's an alternative that still does, while working without Function :

function objectConverter(columns){
    return function(d){
        var o = {};
        columns.forEach(function(name, i){
            o[name] = d[i];
        });
        return o;
    };
}

And, for future reference, here's another one that uses the latest syntax :

const objectConverter = columns => d => Object.fromEntries(columns.map((name, i) => [name, d[i]]));

Thanks

mbostock commented 2 years ago

Related https://github.com/d3/d3-dsv/pull/26#issuecomment-298638569 #80 #87.