DEV Community

Discussion on: Daily Challenge #183 - Automorphic Numbers

Collapse
 
mellen profile image
Matt Ellen • Edited

No regex for this one :(

function autoMorphic(n)
{
  const nsq = n*n;
  const nthpower = Math.floor(Math.log10(n))+1;
  const bigbit = Math.floor(nsq / (10**nthpower)) * (10**nthpower);
  const smallbit = nsq-bigbit;
  return smallbit == n;
}