8000 #7, #8, #11 done · bmoran17/javascript-exercises@5040c27 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5040c27

Browse files
committed
1 parent 070dfa0 commit 5040c27

File tree

6 files changed

+64
-45
lines changed

6 files changed

+64
-45
lines changed

06_leapYears/leapYears.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
const leapYears = function(year) {
2-
if (year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0)) return true
3-
else false;
42

5-
// if (year % 4 === 0) {
6-
// if (year % 100 === 0) {
7-
// if (year % 400 === 0) return true;
8-
// else return false;
9-
// }
10-
// else return true;
11-
// } else return false;
3+
return ((year % 4 === 0) && ((year % 100 !== 0) || (year % 400 === 0))) ? true : false;
4+
5+
// if (year % 4 === 0) {
6+
// if (year % 100 === 0) {
7+
// if (year % 400 === 0) return true;
8+
// else return false;
9+
// }
10+
// else return true;
11+
// } else return false;
1212
};
1313

1414
// Do not edit below this line

07_tempConversion/tempConversion.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
const convertToCelsius = function() {
1+
const convertToCelsius = function(fTemp) {
2+
const temp = ((fTemp - 32) * 5/9);
3+
return (Math.round(temp * 10)/10);
24
};
35

4-
const convertToFahrenheit = function() {
6+
const convertToFahrenheit = function(cTemp) {
7+
const temp = (cTemp * (9/5) + 32);
8+
return (Math.round(temp * 10)/10);
59
};
610

711
// Do not edit below this line

07_tempConversion/tempConversion.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ describe('convertToCelsius', () => {
44
test('works', () => {
55
expect(convertToCelsius(32)).toEqual(0);
66
});
7-
test.skip('rounds to 1 decimal', () => {
7+
test('rounds to 1 decimal', () => {
88
expect(convertToCelsius(100)).toEqual(37.8);
99
});
10-
test.skip('works with negatives', () => {
10+
test('works with negatives', () => {
1111
expect(convertToCelsius(-100)).toEqual(-73.3);
1212
});
1313
});
1414

1515
describe('convertToFahrenheit', () => {
16-
test.skip('works', () => {
16+
test('works', () => {
1717
expect(convertToFahrenheit(0)).toEqual(32);
1818
});
19-
test.skip('rounds to 1 decimal', () => {
19+
test('rounds to 1 decimal', () => {
2020
expect(convertToFahrenheit(73.2)).toEqual(163.8);
2121
});
22-
test.skip('works with negatives', () => {
22+
test('works with negatives', () => {
2323
expect(convertToFahrenheit(-10)).toEqual(14);
2424
});
2525
});

08_calculator/calculator.js

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,37 @@
1-
const add = function() {
2-
1+
const add = function(num1, num2) {
2+
return num1 + num2;
33
};
44

5-
const subtract = function() {
6-
5+
const subtract = function(num1, num2) {
6+
return num1 - num2;
77
};
88

9-
const sum = function() {
10-
9+
const sum = function(array) {
10+
let total = 0;
11+
for (const num of array) {
12+
total += num;
13+
}
14+
return total;
1115
};
1216

13-
const multiply = function() {
14-
17+
const multiply = function(array) {
18+
let total = 1;
19+
for (const num of array) {
20+
total *= num;
21+
}
22+
return total;
1523
};
1624

17-
const power = function() {
18-
25+
const power = function(num1, num2) {
26+
return num1 ** num2;
1927
};
2028

21-
const factorial = function() {
22-
29+
const factorial = function(num) {
30+
let total = 1;
31+
for (let i = num; i > 0 ; i--) {
32+
total *= i;
33+
}
34+
return total
2335
};
2436

2537
// Do not edit below this line

08_calculator/calculator.spec.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,73 +5,73 @@ describe('add', () => {
55
expect(calculator.add(0,0)).toBe(0);
66
});
77

8-
test.skip('adds 2 and 2', () => {
8+
test('adds 2 and 2', () => {
99
expect(calculator.add(2,2)).toBe(4);
1010
});
1111

12-
test.skip('adds positive numbers', () => {
12+
test('adds positive numbers', () => {
1313
expect(calculator.add(2,6)).toBe(8);
1414
});
1515
});
1616

1717
describe('subtract', () => {
18-
test.skip('subtracts numbers', () => {
18+
test('subtracts numbers', () => {
1919
expect(calculator.subtract(10,4)).toBe(6);
2020
});
2121
});
2222

2323
describe('sum', () => {
24-
test.skip('computes the sum of an empty array', () => {
24+
test('computes the sum of an empty array', () => {
2525
expect(calculator.sum([])).toBe(0);
2626
});
2727

28-
test.skip('computes the sum of an array of one number', () => {
28+
test('computes the sum of an array of one number', () => {
2929
expect(calculator.sum([7])).toBe(7);
3030
});
3131

32-
test.skip('computes the sum of an array of two numbers', () => {
32+
test('computes the sum of an array of two numbers', () => {
3333
expect(calculator.sum([7,11])).toBe(18);
3434
});
3535

36-
test.skip('computes the sum of an array of many numbers', () => {
36+
test('computes the sum of an array of many numbers', () => {
3737
expect(calculator.sum([1,3,5,7,9])).toBe(25);
3838
});
3939
});
4040

4141
describe('multiply', () => {
42-
test.skip('multiplies two numbers', () => {
42+
test('multiplies two numbers', () => {
4343
expect(calculator.multiply([2,4])).toBe(8);
4444
});
4545

46-
test.skip('multiplies several numbers', () => {
46+
test('multiplies several numbers', () => {
4747
expect(calculator.multiply([2,4,6,8,10,12,14])).toBe(645120);
4848
});
4949
});
5050

5151
describe('power', () => {
52-
test.skip('raises one number to the power of another number', () => {
52+
test('raises one number to the power of another number', () => {
5353
expect(calculator.power(4,3)).toBe(64); // 4 to third power is 64
5454
});
5555
});
5656

5757
describe('factorial', () => {
58-
test.skip('computes the factorial of 0', () => {
58+
test('computes the factorial of 0', () => {
5959
expect(calculator.factorial(0)).toBe(1); // 0! = 1
6060
});
6161

62-
test.skip('computes the factorial of 1', () => {
62+
test('computes the factorial of 1', () => {
6363
expect(calculator.factorial(1)).toBe(1);
6464
});
6565

66-
test.skip('computes the factorial of 2', () => {
66+
test('computes the factorial of 2', () => {
6767
expect(calculator.factorial(2)).toBe(2);
6868
});
6969

70-
test.skip('computes the factorial of 5', () => {
70+
test('computes the factorial of 5', () => {
7171
expect(calculator.factorial(5)).toBe(120);
7272
});
7373

74-
test.skip('computes the factorial of 10', () => {
74+
test('computes the factorial of 10', () => {
7575
expect(calculator.factorial(10)).toBe(3628800);
7676
});
7777
});

11_getTheTitles/getTheTitles.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
const getTheTitles = function() {
2-
1+
const getTheTitles = function(array) {
2+
const titles = array.map(function (book) {
3+
return book.title;
4+
})
5+
return titles;
36
};
47

58
// Do not edit below this line

0 commit comments

Comments
 (0)
0