dabidabidesh

perfectNumber0

Jun 17th, 2020
322
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. perfectNumber0 = (num) => {
  2.   'use strict'
  3.  
  4.   const getPositiveDivisors = num => {
  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.     return arr
  13.   }
  14.  
  15.   const getSum = arr => {
  16.     let sum = 0
  17.     for (let i = 0; i < arr.length; i++)
  18.       sum += arr[i]
  19.  
  20.     return sum
  21.   }
  22.  
  23.   let arr = [],
  24.     sum = 0
  25.  
  26.   arr = getPositiveDivisors(num)
  27.   sum = getSum(arr)
  28.  
  29.   if (sum === num)
  30.     console.log('We have a perfect number!')
  31.   else
  32.     console.log('It\'s not so perfect.')
  33. }
RAW Paste Data