1
var maxValue = function (n, x) {4
// if the number if positive, find the first5
// number that is less than x7
for (i = 0; i < n.length; i++) {8
if (Number(n[i]) < x) break;11
// if the number is negative, find the first12
// number that is greater than x14
for (i = 1; i < n.length; i++) {15
if (Number(n[i]) > x) break;19
// return the string with x inserted at the found index20
return n.slice(0, i) + x + n.slice(i);23
///////////////// short hand ////////////////////25
var maxValue = function (n, x) {28
for (i = 0; i < n.length; i++) {29
if (Number(n[i]) < x) break;32
for (i = 1; i < n.length; i++) {33
if (Number(n[i]) > x) break;36
return n.slice(0, i) + x + n.slice(i);