You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Check whether a number (from 1 to 100) is prime or not
constprimes=[2,3,5,7];functionisPrime(num){constnearestPerfectSq=Math.floor(Math.sqrt(num));for(letiofprimes){letisDivisible=(num%i===0);if(i<=nearestPerfectSq&&isDivisible)returnfalse;}returntrue;}letnums=Array(99).fill(0).map((_,i)=>i+2);for(letnumofnums){letis=isPrime(num);is&&console.log(`${num} is prime`);}
Check whether a number is Armstrong number or not
functionisArmstrong(num){letnumStr=`${num}`letd1=+numStr[0];letd2=+numStr[1];letd3=+numStr[2];returnnum===(d1**3+d2**3+d3**3);}letnums=Array(900).fill(0).map((_,i)=>i+100);for(letnumofnums){letis=isArmstrong(num);is&&console.log(`${num} is armstrong.`);}// 153 is armstrong.// 370 is armstrong.// 371 is armstrong.// 407 is armstrong.