Write a function solution that given a three digit integer N and Integer K, returns the maximum possible three digit value that can be obtained by performing at most K increases by 1 of any digit in N
function maximumPossibleThree(n, k) {
let arr = [...n.toString()].map(Number);
let f = false;
let resStr = arr.map(item => {
if (item + k < 10 && !f) {
f = true;
return item + k;
} else {
return item;
}
});
let res = Number(resStr.join(''))
console.log(res);
}
Comments
Leave a comment