Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d6eb962

Browse files
🐛 FIX: Some fixes
1 parent 35ecee1 commit d6eb962

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

‎Project-Euler/Problem021.js

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @param {Number} maxNum
1414
* @returns {Number} Sum of all amicable numbers under maxNum
1515
*/
16-
export const sumAmicableNum = (maxNum) => {
16+
export const sumAmicableNums = (maxNum) => {
1717
const amicNums = []
1818

1919
for (let i = 1; i < maxNum; i++) {
@@ -23,23 +23,13 @@ export const sumAmicableNum = (maxNum) => {
2323
amicNums.push(i, left)
2424
}
2525
}
26-
return amicNums.reduce((a, b) => {
27-
a += b
28-
return a
29-
})
26+
return amicNums.reduce((a, b) => a + b, 0)
3027
}
3128

3229
const d = (num) => {
3330
const output = []
3431
for (let i = 1; i < num; i++) {
35-
if (!(num % i)) { output.push(i) }
36-
}
37-
if (!output.length) {
38-
return 0
39-
} else {
40-
return output.reduce((a, b) => {
41-
a += b
42-
return a
43-
})
32+
if (num % i === 0) { output.push(i) }
4433
}
34+
return output.reduce((a, b) => a + b, 0)
4535
}

‎Project-Euler/test/Problem021.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { sumAmicableNum } from '../Problem021.js'
1+
import { sumAmicableNums } from '../Problem021.js'
22

33
describe('Amicable numbers', () => {
44
// Project Euler Condition Check
5-
test('if the number is 10000', () => {
6-
expect(sumAmicableNum(10000)).toBe(31626)
5+
test('if the limit is 10000', () => {
6+
expect(sumAmicableNums(10000)).toBe(31626)
77
})
88
})

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /