Answer to Question #310504 in HTML/JavaScript Web Application for test

Question #310504

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


1
Expert's answer
2022-03-13T19:07:21-0400
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);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS