Find next higher natural number that is divisble by another number
Write a function that takes two numbers, say x and y, as arguments. We need to check if x is divisible by y. If yes, then return x. If not, return the next higher natural number that is divisible by y.
const findDivisble = (x, y) => { if (x % y === 0) return x; if(y < 0) return 0; const divisor = parseInt(x / y); return divisor * y + y; } console.log(findDivisble(7, 3)); // 9