An Elegant Pairing Function implementation for JavaScript

When x and y are non-negative integers, elegantPair(x, y) function outputs single non-negative integer that is uniquely associated with that pair. The inverse function elegantUnpair(z) outputs the pair assscociated with each non-negative integer z.

  //An Elegant Pairing Function by Matthew Szudzik @ Wolfram Research, Inc.
function elegantPair(x, y) {
  return (x >= y) ? (x * x + x + y) : (y * y + x);
}

function elegantUnpair(z) {
  var sqrtz = Math.floor(Math.sqrt(z)),
    sqz = sqrtz * sqrtz;
  return ((z - sqz) >= sqrtz) ? [sqrtz, z - sqz - sqrtz] : [z - sqz, sqrtz];
}


6,300 3 8