Find duplicate in linear time and space
I'm not a big fan of the functional solution for following reasons:


the pointless use of the some() method, because its callback always returns false. This is this possibly an error? The call would short-circuit, if Boolean(ret = x) weren't negated. But even then some() would be the wrong choice, because it's just used for short-circuiting. I believe find() would be a better choice.
the conditional expression together with Boolean(...) expressions are a bit if a crutch. The conditional expression seems to be only used to be shorter that an full if, but that requires Boolean(), so that it still returns a boolean value needed for some().


Using find() I've come up with

const findDuplicate = lst =&gt; {
  const set = new Set();
  return lst.find(
    x =&gt; set.has(x) || !set.add(x)
  );
};


However I do admit it may be a bit cryptic.