dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
1.2 KiB
1.2 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 6925e2068081f40f549ced1c | Challenge 138: Sum of Divisors | 28 | challenge-138 |
--description--
Given a positive integer, return the sum of all its divisors.
- A divisor is any integer that divides the number evenly (the remainder is
0). - Only count each divisor once.
For example, given 6, return 12 because the divisors of 6 are 1, 2, 3, and 6, and the sum of those is 12.
--hints--
sumDivisors(6) should return 12.
assert.equal(sumDivisors(6), 12);
sumDivisors(13) should return 14.
assert.equal(sumDivisors(13), 14);
sumDivisors(28) should return 56.
assert.equal(sumDivisors(28), 56);
sumDivisors(84) should return 224.
assert.equal(sumDivisors(84), 224);
sumDivisors(549) should return 806.
assert.equal(sumDivisors(549), 806);
sumDivisors(9348) should return 23520.
assert.equal(sumDivisors(9348), 23520);
--seed--
--seed-contents--
function sumDivisors(n) {
return n;
}
--solutions--
function sumDivisors(n) {
let sum = 0;
for (let i = 1; i <= n; i++) {
if (n % i === 0) {
sum += i;
}
}
return sum;
}