Avoid duplicate entries using a sign change
JavaScript

Take a conventional algorithm and write it with a bug:

function merge(a, b) {
  var ai = 0, bi = 0, oi = 0;
  var o = [];
  while (ai &lt; a.length &amp;&amp; bi &lt; b.length) {
    var v = a[ai] &lt; b[bi] ? a[ai++] : b[bi++];
    if (v !== o[oi + 1]) {
      o[oi++] = v;
    }
  }
  while (ai &lt; a.length) o[oi++] = a[ai++];
  while (bi &lt; b.length) o[oi++] = b[bi++];
  return o;
}


This code contains exactly one literal 1. If it is changed to -1, then duplicates will be removed. It can be used on any comparable values.