Finished
33// convenience to get you started writing code faster.
44//
55
6export const sum = () => {
7 throw new Error('Remove this line and implement the function');
6export const sum = (magicalItems, level) => {
7 // Edge Case: Level is 0 or 1, no multiples possible
8 if (level <= 1) {
9 return 0;
10 }
11
12 // Edge Case: Empty list of magical items
13 if (!magicalItems || magicalItems.length === 0) {
14 return 0;
15 }
16
17 const multiples = new Set();
18
19 // For each magical item base value
20 for (const baseValue of magicalItems) {
21 // Edge Case: Negative or zero base value
22 if (baseValue <= 0) {
23 continue;
24 }
25
26 // Edge Case: Base value greater than or equal to level number
27 if (baseValue >= level) {
28 continue;
29 }
30
31 // Find all multiples of baseValue less than level
32 for (let multiple = baseValue; multiple < level; multiple += baseValue) {
33 multiples.add(multiple);
34 }
35 }
36
37 // Sum all unique multiples
38 let sum = 0;
39 for (const multiple of multiples) {
40 sum += multiple;
41 }
42
43 return sum;
844};
45
46// Handled Edge Cases: Level is 0 or 1, empty list of magical items, negative or zero base values, base values greater than or equal to level number
Test NameStatus
no multiples within limit
Pass
one factor has multiples within limit
Pass
more than one multiple within limit
Pass
more than one factor with multiples within limit
Pass
each multiple is only counted once
Pass
a much larger limit
Pass
three factors
Pass
factors not relatively prime
Pass
some pairs of factors relatively prime and some not
Pass
one factor is a multiple of another
Pass
much larger factors
Pass
all numbers are multiples of 1
Pass
no factors means an empty sum
Pass
the only multiple of 0 is 0
Pass
the factor 0 does not affect the sum of multiples of other factors
Pass
solutions using include-exclude must extend to cardinality greater than 3
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.