-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3s-and-5s.js
71 lines (61 loc) · 1.56 KB
/
3s-and-5s.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
var test = require('mocha').it,
expect = require('chai').expect, // Use `expect(X).to.be` et al
assert = require('chai').assert; // OR use `assert.equal` etc
test(multOf3s, function(){
expect(multOf3s(5)).to.equal(3);
expect(multOf3s(6)).to.equal(9);
expect(multOf3s (10)).to.equal(18);
expect(multOf3s (12)).to.equal(30);
expect(multOf3s (0)).to.equal(0);
expect(multOf3s (20)).to.equal(63);
}); // END test 3s
// function for sum of multiples of 3
//parameter N is a Number
// var sum is a number and var n
//returns a number
function multOf3s (N){
var sum = 0, n = 0;
for (n=0; n<=N; n++){
if (n % 3 === 0){
sum += n;
}
}
return sum;
}
test(multOf5s, function(){
expect(multOf5s(5)).to.equal(5);
expect(multOf5s(6)).to.equal(5);
expect(multOf5s (10)).to.equal(15);
expect(multOf5s (12)).to.equal(15);
expect(multOf5s (0)).to.equal(0);
expect(multOf5s (20)).to.equal(50);
expect(multOf5s (50)).to.equal(275);
expect(multOf5s (1000)).to.equal(100500);
});
function multOf5s (N){
var sum = 0, n = 0;
for (n=0; n<=N; n++){
if (n % 5 === 0){
sum += n;
}
}
return sum;
}
test(multOf3s5s, function(){
expect(mult3s5s(5)).to.equal(8);
expect(mult3s5s(10)).to.equal(33);
expect(mult3s5s(12)).to.equal(45);
expect(mult3s5s(15)).to.equal(60);
expect(mult3s5s(0)).to.equal(0);
expect(mult3s5s(20)).to.equal(98);
expect(mult3s5s(50)).to.equal(593);
});
function multOf3s5s (N){
var sum = 0, n = 0
for (n=0; n<=N; n++){
if (n % 3 === 0 || n % 5 === 0){
sum += n;
}
}
return sum
}