We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
constisKapreka=(str,str2)=>{constlen=str.length;const[l,r]=[str2.slice(0,-len)||0,str2.slice(-len)]constsum=[l,r].map(e=>parseInt(e)).reduce((a,b)=>a+b,0);if(sum==parseInt(str))returntrue;returnfalse;}functionkaprekarNumbers(p,q){// Write your code hereconstcontainer=[];for(leti=p;i<=q;i++){if(!isKapreka(String(i),String(i**2)))continue;container.push(i)}if(container.length)returnconsole.log(...container);returnconsole.log('INVALIDRANGE')}
Cookie support is required to access HackerRank
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 →
Javascript