Here is my Javascript version of Kaprekar numbers
function getSubInt(str, start, end){ if(end == undefined) return parseInt(str.substring(start)) || 0; return parseInt(str.substring(0, end)) || 0; } function getKaprekar(max){ var kaprekar = [], count = 0; for(var i = 1; count < max; i++){ var sqr = (i * i).toString(); var middle = (sqr.length / 2); if((getSubInt(sqr, 0, middle) + getSubInt(sqr, middle)) === i){ kaprekar.push(i); count++; } } return kaprekar; } console.log(getKaprekar(8).toString());
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.
Here is my Javascript version of Kaprekar numbers