DEV Community

Discussion on: how not to use reduce

Collapse
 
rkichenama profile image
Richard Kichenama

I believe you are right, though the implementation of Set in javascript should give O(1) or at most sublinear lookups with a hashing function. Based on that, I assume the following would be equivalent without the new data type.

const jObj = ys.reduce((t, c) => { t[c] = true; return t; });
xs.find(x => ( jObj[x] ));
Thread Thread
 
ycmjason profile image
YCM Jason

ya except I'd not use a reduce.