Mathematics
Algorithms
Logic
Numbers
Data Types
Write a function that checks if a number is a perfect number.
(All divisors except itself when added up equal the original number)
const isPerfect = n =>
Array(n - 1).fill(1).map((e, i) => e + i).filter(e => n % e === 0).reduce((a, b) => a + b) === n
Test.expect(isPerfect(6));
Test.expect(isPerfect(28));
Test.expect(!isPerfect(16));
Test.expect(!isPerfect(9));