• + 0 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")
    }