File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -5,9 +5,11 @@ Find the sum of all the multiples of 3 or 5 below the provided parameter value n
5
5
*/
6
6
7
7
const multiplesThreeAndFive = ( num ) => {
8
+ if ( num < 1 ) throw new Error ( 'No natural numbers exist below 1' )
9
+
8
10
let total = 0
9
11
// total for calculating the sum
10
- for ( let i = 0 ; i < num ; i ++ ) {
12
+ for ( let i = 1 ; i < num ; i ++ ) {
11
13
if ( i % 3 === 0 || i % 5 === 0 ) {
12
14
total += i
13
15
}
Original file line number Diff line number Diff line change
1
+ import { multiplesThreeAndFive } from '../Problem001.js'
2
+
3
+ describe ( 'Sum of multiples of 3 or 5' , ( ) => {
4
+ it ( 'should throw error when number is negative number' , ( ) => {
5
+ expect ( ( ) => multiplesThreeAndFive ( - 24 ) ) . toThrowError ( 'No natural numbers exist below 1' )
6
+ } )
7
+ it ( 'should throw error when number is 0' , ( ) => {
8
+ expect ( ( ) => multiplesThreeAndFive ( 0 ) ) . toThrowError ( 'No natural numbers exist below 1' )
9
+ } )
10
+ test ( 'if the number is greater than 0' , ( ) => {
11
+ expect ( multiplesThreeAndFive ( 10 ) ) . toBe ( 23 )
12
+ } )
13
+ // Project Euler Condition Check
14
+ test ( 'if the number is 1000' , ( ) => {
15
+ expect ( multiplesThreeAndFive ( 1000 ) ) . toBe ( 233168 )
16
+ } )
17
+ } )
You can’t perform that action at this time.
0 commit comments