Generate lazy values Related: Program my microwave oven. Inspired by Generate lazy microwave input.

The lazy value of the non-negative integer N is the smallest of the integers that are closest to N while all their digits are identical.

Return (by any means) the lazy value of a given (by any means) N.

N ≤ the largest integer that your language represents in non-exponent form by default. 1000000 (A lot of interesting solutions are lost because of this too-high requirement.)

Test cases:

   0 →    0
   8 →    8
   9 →    9
  10 →    9
  16 →   11
  17 →   22
  27 →   22
  28 →   33
 100 →   99
 105 →   99
 106 →  111
 610 →  555
 611 →  666
7221 → 6666
7222 → 7777 




The colleague in question proved that there will be no ties: Except for 9/11, 99/111, etc. for which one is shorter than the other, two consecutive valid answers are always an odd distance apart, so no integer can be exactly equidistant from them.
JavaScript (ES6), 31 bytes

n=&gt;~-(n*9+4).toPrecision(1)/9|0


Directly computes the lazy value for each n.

Edit: Only works up to 277777778 due to the limitations of JavaScript's integer type. Alternative versions:

n=&gt;((n*9+4).toPrecision(1)-1)/9&gt;&gt;&gt;0


35 bytes, works up to 16666666667.

n=&gt;((n=(n*9+4).toPrecision(1))-n[0])/9


38 bytes, works up to 944444444444443. But that's still some way short of 253 which is 9007199254740992.