dabidabidesh

perfectNumber

Jun 17th, 2020
315
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //15 EXERCISE: FUNCTIONS/08. Perfect Number.js
  2. perfectNumber = (num) => {
  3.   'use strict'
  4.  
  5.   let arr = []
  6.   for (let i = 1, j = 0; i < num; i++)
  7.     if (num % i === 0) {
  8.       arr[j] = i
  9.       j++
  10.     }
  11.  
  12.   let sum = 0
  13.   for (let i = 0; i < arr.length; i++)
  14.     sum += arr[i]
  15.  
  16.   if (sum === num)
  17.     console.log('We have a perfect number!')
  18.   else
  19.     console.log('It\'s not so perfect.')
  20. }
  21. perfectNumber(6)
RAW Paste Data