DEV Community

Discussion on: What’s your alternative solution? Challenge #27

Collapse
 
curtisfenner profile image
Curtis Fenner

The given algorithm is simple, but runs in quadratic time. You can use Sets to make the includes check faster.

const inLeft = new Set(left);
const inRight = new Set(right);
return left.filter(x => !inRight.has(x)).concat(right.filter(x => !inLeft has(x));