Ad
Mathematics
Algorithms
Logic
Numbers
Data Types

You can declare Array with running numbers up by using [...Array(n).keys]. Then if you want it start from 1, you just increase array size then slice it of.

Code
Diff
  • const isPerfect = n => 
      [...Array(n).keys()].slice(1).filter(e => !(n % e)).reduce((a, b) => a + b) === n
    • const isPerfect = n =>
    • Array(n - 1).fill(1).map((e, i) => e + i).filter(e => n % e === 0).reduce((a, b) => a + b) === n
    • [...Array(n).keys()].slice(1).filter(e => !(n % e)).reduce((a, b) => a + b) === n