I'm not pretty good at coding but I tried in my own way :) just for fun and I hope is ok.
Here is my JS version:
var numbers = [1, 9, 45, 55, 99, 297, 703, 999]; console.log("Kaprekar"); for (var i = 0; i < numbers.length; i++) { var sq = numbers[i] * numbers[i]; if (sq.toString().length % 2 === 0) { var kap = sq.toString().split(""); var left = ""; var right = ""; for (var j = 0; j < kap.length; j++) { if (j < kap.length / 2) { left += kap[j].toString(); } else { right += kap[j].toString(); } } if ((parseInt(left) + parseInt(right)) === numbers[i]) { console.log(numbers[i] + "^2 = " + sq + " -> " + left + " + " + right + " = " + (parseInt(left) + parseInt(right))); } } else { console.log(numbers[i] + " Is not Kaprekar"); } }
Here is the JSFiddle link: jsfiddle.net/kw95nv45/2/
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I'm not pretty good at coding but I tried in my own way :) just for fun and I hope is ok.
Here is my JS version:
Here is the JSFiddle link:
jsfiddle.net/kw95nv45/2/