Advertisement
Spocoman

08. Perfect Number

Jan 28th, 2022
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve (num) {
  2.  
  3.     let sumDivisors = 0;
  4.  
  5.     for (let i = 1; i <= num; i++) {
  6.         if (num % i === 0) {
  7.             sumDivisors += i;
  8.         }
  9.         if (sumDivisors >= num){
  10.             console.log(sumDivisors === num ? "We have a perfect number!" : "It's not so perfect.");
  11.             break;
  12.         }
  13.     }
  14. }
  15.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement