-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3s-and-5s.js
70 lines (54 loc) · 1.75 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
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('threes', function(){
expect(threes).to.be.a("function");
expect(threes(0)).to.deep.equal([]);
expect(threes(4)).to.deep.equal([3]);
}); // END test 3s
test('sumoffives', function(){
assert.equal(sumoffives([5]), 5);
assert.equal(sumoffives([5, 10, 15]), 30);
assert.equal(sumoffives([5, 10, 15, 20, 25, 30, 35, 40, 45]), 225);
// expect(fives(10)).to.equal([5])
// expect(fives(20)).to.equal([5, 10, 15])
// expect(fives(50)).to.equal([5, 10, 15, 20, 25, 30, 35, 40, 45])
}); // END test 5s
//could not get the tests to work, but i checked the function
// in the console and it runs.
function threes(N){
var multiples = [];
var increment = 0;
while (incremet < N){
console.log(increment);
increment++;
}
if (N > 3){
multiples.push(3); // [3]
}
if (N > 6){
//return [3,6];
multiples.push(6); // [3, 6]
}
if (N > 9){
multiples.push(9);
}
} {
return multiples;
}
var three = [];
var five = [];
var both = [];
function Multiples (){
for(var i = 1; i < 1000; i++){
if (i % 3 === 0 && i % 5 === 0){ //works if i is divisable by 3 and 5 has no remainder
both.push(i); //var both = [array of both 3 and 5]
} else if (i % 3 === 0){ //works if i is divisable by 3 has no remainders
three.push(i); //var three = [array of multiples of 3]
} else if (i % 5 === 0){ //works if i is divisable by 5 has no remainders
five.push(i); //var five = [array of multiples of 5]
}
}
var All = three.concat(five, both); //joins all 3 arrays
for (var x = 0, sum = 0; x < All.length; sum += All[x++]); //adds on to each iteration
}