You are viewing a single comment's thread. Return to all comments →
my js solution
function kaprekarNumbers(p, q) { // Write your code here let arr = [] if(p <= 1) arr.push(1) for(let i = p; i <= q; i++){ let square = String(i * i); let first = square.slice(0, square.length/2) let second = square.slice(square.length/2, square.length) parseInt(first) + parseInt(second) == i && arr.push(i) } arr.length > 0 ? console.log(arr.toString().split(',').join(' ')) : console.log("INVALID RANGE") }
Seems like cookies are disabled on this browser, please enable them to open this website
Modified Kaprekar Numbers
You are viewing a single comment's thread. Return to all comments →
my js solution