Skip to content

Commit 4a11236

Browse files
committed
Update files
1 parent fb1a2db commit 4a11236

31 files changed

+571
-449
lines changed

Diff for: 01_helloWorld/solution/helloWorld-solution.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const helloWorld = function () {
2-
return 'Hello, World!';
2+
return "Hello, World!";
33
};
44

55
module.exports = helloWorld;

Diff for: 01_helloWorld/solution/helloWorld-solution.spec.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const helloWorld = require('./helloWorld-solution');
1+
const helloWorld = require("./helloWorld");
22

3-
describe('Hello World', function () {
4-
test('says "Hello, World!"', function () {
5-
expect(helloWorld()).toEqual('Hello, World!');
6-
});
3+
describe("Hello World", function () {
4+
test('says "Hello, World!"', function () {
5+
expect(helloWorld()).toEqual("Hello, World!");
6+
});
77
});

Diff for: 02_repeatString/solution/repeatString-solution.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
const repeatString = function (word, times) {
2-
if (times < 0) return 'ERROR';
3-
let string = '';
4-
for (let i = 0; i < times; i++) {
5-
string += word;
6-
}
7-
return string;
2+
if (times < 0) return "ERROR";
3+
let string = "";
4+
for (let i = 0; i < times; i++) {
5+
string += word;
6+
}
7+
return string;
88
};
99

1010
module.exports = repeatString;
+31-33
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,39 @@
1-
const repeatString = require('./repeatString-solution');
1+
const repeatString = require("./repeatString");
22

3-
describe('repeatString', () => {
4-
test('repeats the string', () => {
5-
expect(repeatString('hey', 3)).toEqual('heyheyhey');
6-
});
7-
test.skip('repeats the string many times', () => {
8-
expect(repeatString('hey', 10)).toEqual(
9-
'heyheyheyheyheyheyheyheyheyhey'
10-
);
11-
});
12-
test.skip('repeats the string 1 times', () => {
13-
expect(repeatString('hey', 1)).toEqual('hey');
14-
});
15-
test.skip('repeats the string 0 times', () => {
16-
expect(repeatString('hey', 0)).toEqual('');
17-
});
18-
test.skip('returns ERROR with negative numbers', () => {
19-
expect(repeatString('hey', -1)).toEqual('ERROR');
20-
});
21-
test.skip('repeats the string a random amount of times', function () {
22-
/*The number is generated by using Math.random to get a value from between
3+
describe("repeatString", () => {
4+
test("repeats the string", () => {
5+
expect(repeatString("hey", 3)).toEqual("heyheyhey");
6+
});
7+
test.skip("repeats the string many times", () => {
8+
expect(repeatString("hey", 10)).toEqual("heyheyheyheyheyheyheyheyheyhey");
9+
});
10+
test.skip("repeats the string 1 times", () => {
11+
expect(repeatString("hey", 1)).toEqual("hey");
12+
});
13+
test.skip("repeats the string 0 times", () => {
14+
expect(repeatString("hey", 0)).toEqual("");
15+
});
16+
test.skip("returns ERROR with negative numbers", () => {
17+
expect(repeatString("hey", -1)).toEqual("ERROR");
18+
});
19+
test.skip("repeats the string a random amount of times", function () {
20+
/*The number is generated by using Math.random to get a value from between
2321
0 to 1, when this is multiplied by 1000 and rounded down with Math.floor it
2422
equals a number between 0 to 999 (this number will change everytime you run
2523
the test).*/
2624

27-
// DO NOT use Math.floor(Math.random() * 1000) in your code,
28-
// this test generates a random number, then passes it into your code with a function parameter.
29-
// If this doesn't make sense, you should go read about functions here: https://www.theodinproject.com/paths/foundations/courses/foundations/lessons/fundamentals-part-3
30-
const number = Math.floor(Math.random() * 1000);
31-
/*The .match(/((hey))/g).length is a regex that will count the number of heys
25+
// DO NOT use Math.floor(Math.random() * 1000) in your code,
26+
// this test generates a random number, then passes it into your code with a function parameter.
27+
// If this doesn't make sense, you should go read about functions here: https://www.theodinproject.com/paths/foundations/courses/foundations/lessons/fundamentals-part-3
28+
const number = Math.floor(Math.random() * 1000);
29+
/*The .match(/((hey))/g).length is a regex that will count the number of heys
3230
in the result, which if your function works correctly will equal the number that
3331
was randomaly generated. */
34-
expect(repeatString('hey', number).match(/((hey))/g).length).toEqual(
35-
number
36-
);
37-
});
38-
test.skip('works with blank strings', () => {
39-
expect(repeatString('', 10)).toEqual('');
40-
});
32+
expect(repeatString("hey", number).match(/((hey))/g).length).toEqual(
33+
number
34+
);
35+
});
36+
test.skip("works with blank strings", () => {
37+
expect(repeatString("", 10)).toEqual("");
38+
});
4139
});

Diff for: 03_reverseString/solution/reverseString-solution.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const reverseString = function (string) {
2-
return string.split('').reverse().join('');
2+
return string.split("").reverse().join("");
33
};
44

55
module.exports = reverseString;
+14-14
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
const reverseString = require('./reverseString-solution');
1+
const reverseString = require("./reverseString");
22

3-
describe('reverseString', () => {
4-
test('reverses single word', () => {
5-
expect(reverseString('hello')).toEqual('olleh');
6-
});
3+
describe("reverseString", () => {
4+
test("reverses single word", () => {
5+
expect(reverseString("hello")).toEqual("olleh");
6+
});
77

8-
test.skip('reverses multiple words', () => {
9-
expect(reverseString('hello there')).toEqual('ereht olleh');
10-
});
8+
test.skip("reverses multiple words", () => {
9+
expect(reverseString("hello there")).toEqual("ereht olleh");
10+
});
1111

12-
test.skip('works with numbers and punctuation', () => {
13-
expect(reverseString('123! abc!')).toEqual('!cba !321');
14-
});
15-
test.skip('works with blank strings', () => {
16-
expect(reverseString('')).toEqual('');
17-
});
12+
test.skip("works with numbers and punctuation", () => {
13+
expect(reverseString("123! abc!")).toEqual("!cba !321");
14+
});
15+
test.skip("works with blank strings", () => {
16+
expect(reverseString("")).toEqual("");
17+
});
1818
});

Diff for: 04_removeFromArray/solution/removeFromArray-solution.js

+16-19
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
11
// we have 2 solutions here, an easier one and a more advanced one.
2-
// The easiest way to get an array of all of the arguments that are passed to a function
2+
// The easiest way to get an array of the rest of the arguments that are passed to a function
33
// is using the rest operator. If this is unfamiliar to you look it up!
4-
const removeFromArray = function (...args) {
5-
// the very first item in our list of arguments is the array, we pull it out with args[0]
6-
const array = args[0];
7-
// create a new empty array
8-
const newArray = [];
9-
// use forEach to go through the array
10-
array.forEach((item) => {
11-
// push every element into the new array
12-
// UNLESS it is included in the function arguments
13-
// so we create a new array with every item, except those that should be removed
14-
if (!args.includes(item)) {
15-
newArray.push(item);
16-
}
17-
});
18-
// and return that array
19-
return newArray;
4+
const removeFromArray = function (array, ...args) {
5+
// create a new empty array
6+
const newArray = [];
7+
// use forEach to go through the array
8+
array.forEach((item) => {
9+
// push every element into the new array
10+
// UNLESS it is included in the function arguments
11+
// so we create a new array with every item, except those that should be removed
12+
if (!args.includes(item)) {
13+
newArray.push(item);
14+
}
15+
});
16+
// and return that array
17+
return newArray;
2018
};
2119

2220
// A simpler, but more advanced way to do it is to use the 'filter' function,
2321
// which basically does what we did with the forEach above.
2422

25-
// var removeFromArray = function(...args) {
26-
// const array = args[0]
23+
// var removeFromArray = function(array, ...args) {
2724
// return array.filter(val => !args.includes(val))
2825
// }
2926
//
+23-26
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
1-
const removeFromArray = require('./removeFromArray-solution');
1+
const removeFromArray = require("./removeFromArray");
22

3-
describe('removeFromArray', () => {
4-
test('removes a single value', () => {
5-
expect(removeFromArray([1, 2, 3, 4], 3)).toEqual([1, 2, 4]);
6-
});
7-
test.skip('removes multiple values', () => {
8-
expect(removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]);
9-
});
10-
test.skip('ignores non present values', () => {
11-
expect(removeFromArray([1, 2, 3, 4], 7, 'tacos')).toEqual([1, 2, 3, 4]);
12-
});
13-
test.skip('ignores non present values, but still works', () => {
14-
expect(removeFromArray([1, 2, 3, 4], 7, 2)).toEqual([1, 3, 4]);
15-
});
16-
test.skip('can remove all values', () => {
17-
expect(removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)).toEqual([]);
18-
});
19-
test.skip('works with strings', () => {
20-
expect(removeFromArray(['hey', 2, 3, 'ho'], 'hey', 3)).toEqual([
21-
2,
22-
'ho',
23-
]);
24-
});
25-
test.skip('only removes same type', () => {
26-
expect(removeFromArray([1, 2, 3], '1', 3)).toEqual([1, 2]);
27-
});
3+
describe("removeFromArray", () => {
4+
test("removes a single value", () => {
5+
expect(removeFromArray([1, 2, 3, 4], 3)).toEqual([1, 2, 4]);
6+
});
7+
test.skip("removes multiple values", () => {
8+
expect(removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]);
9+
});
10+
test.skip("ignores non present values", () => {
11+
expect(removeFromArray([1, 2, 3, 4], 7, "tacos")).toEqual([1, 2, 3, 4]);
12+
});
13+
test.skip("ignores non present values, but still works", () => {
14+
expect(removeFromArray([1, 2, 3, 4], 7, 2)).toEqual([1, 3, 4]);
15+
});
16+
test.skip("can remove all values", () => {
17+
expect(removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)).toEqual([]);
18+
});
19+
test.skip("works with strings", () => {
20+
expect(removeFromArray(["hey", 2, 3, "ho"], "hey", 3)).toEqual([2, "ho"]);
21+
});
22+
test.skip("only removes same type", () => {
23+
expect(removeFromArray([1, 2, 3], "1", 3)).toEqual([1, 2]);
24+
});
2825
});

Diff for: 05_sumAll/solution/sumAll-solution.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
const sumAll = function (min, max) {
2-
if (!Number.isInteger(min) || !Number.isInteger(max)) return 'ERROR';
3-
if (min < 0 || max < 0) return 'ERROR';
4-
if (min > max) {
5-
const temp = min;
6-
min = max;
7-
max = temp;
8-
}
9-
let sum = 0;
10-
for (let i = min; i < max + 1; i++) {
11-
sum += i;
12-
}
13-
return sum;
2+
if (!Number.isInteger(min) || !Number.isInteger(max)) return "ERROR";
3+
if (min < 0 || max < 0) return "ERROR";
4+
if (min > max) {
5+
const temp = min;
6+
min = max;
7+
max = temp;
8+
}
9+
let sum = 0;
10+
for (let i = min; i < max + 1; i++) {
11+
sum += i;
12+
}
13+
return sum;
1414
};
1515

1616
module.exports = sumAll;

Diff for: 05_sumAll/solution/sumAll-solution.spec.js

+23-20
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1-
const sumAll = require('./sumAll-solution');
1+
const sumAll = require("./sumAll");
22

3-
describe('sumAll', () => {
4-
test('sums numbers within the range', () => {
5-
expect(sumAll(1, 4)).toEqual(10);
6-
});
7-
test.skip('works with large numbers', () => {
8-
expect(sumAll(1, 4000)).toEqual(8002000);
9-
});
10-
test.skip('works with larger number first', () => {
11-
expect(sumAll(123, 1)).toEqual(7626);
12-
});
13-
test.skip('returns ERROR with negative numbers', () => {
14-
expect(sumAll(-10, 4)).toEqual('ERROR');
15-
});
16-
test.skip('returns ERROR with non-number parameters', () => {
17-
expect(sumAll(10, '90')).toEqual('ERROR');
18-
});
19-
test.skip('returns ERROR with non-number parameters', () => {
20-
expect(sumAll(10, [90, 1])).toEqual('ERROR');
21-
});
3+
describe("sumAll", () => {
4+
test("sums numbers within the range", () => {
5+
expect(sumAll(1, 4)).toEqual(10);
6+
});
7+
test.skip("works with large numbers", () => {
8+
expect(sumAll(1, 4000)).toEqual(8002000);
9+
});
10+
test.skip("works with larger number first", () => {
11+
expect(sumAll(123, 1)).toEqual(7626);
12+
});
13+
test.skip("returns ERROR with negative numbers", () => {
14+
expect(sumAll(-10, 4)).toEqual("ERROR");
15+
});
16+
test.skip("returns ERROR with non-integer parameters", () => {
17+
expect(sumAll(2.5, 4)).toEqual("ERROR");
18+
});
19+
test.skip("returns ERROR with non-number parameters", () => {
20+
expect(sumAll(10, "90")).toEqual("ERROR");
21+
});
22+
test.skip("returns ERROR with non-number parameters", () => {
23+
expect(sumAll(10, [90, 1])).toEqual("ERROR");
24+
});
2225
});

Diff for: 06_leapYears/solution/leapYears-solution.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const leapYears = function (year) {
2-
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
2+
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
33
};
44

55
module.exports = leapYears;

Diff for: 06_leapYears/solution/leapYears-solution.spec.js

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
const leapYears = require('./leapYears-solution');
1+
const leapYears = require("./leapYears");
22

3-
describe('leapYears', () => {
4-
test('works with non century years', () => {
5-
expect(leapYears(1996)).toBe(true);
6-
});
7-
test.skip('works with non century years', () => {
8-
expect(leapYears(1997)).toBe(false);
9-
});
10-
test.skip('works with ridiculously futuristic non century years', () => {
11-
expect(leapYears(34992)).toBe(true);
12-
});
13-
test.skip('works with century years', () => {
14-
expect(leapYears(1900)).toBe(false);
15-
});
16-
test.skip('works with century years', () => {
17-
expect(leapYears(1600)).toBe(true);
18-
});
19-
test.skip('works with century years', () => {
20-
expect(leapYears(700)).toBe(false);
21-
});
3+
describe("leapYears", () => {
4+
test("works with non century years", () => {
5+
expect(leapYears(1996)).toBe(true);
6+
});
7+
test.skip("works with non century years", () => {
8+
expect(leapYears(1997)).toBe(false);
9+
});
10+
test.skip("works with ridiculously futuristic non century years", () => {
11+
expect(leapYears(34992)).toBe(true);
12+
});
13+
test.skip("works with century years", () => {
14+
expect(leapYears(1900)).toBe(false);
15+
});
16+
test.skip("works with century years", () => {
17+
expect(leapYears(1600)).toBe(true);
18+
});
19+
test.skip("works with century years", () => {
20+
expect(leapYears(700)).toBe(false);
21+
});
2222
});
+6-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
const ftoc = function (f) {
2-
return Math.round((f - 32) * (5 / 9) * 10) / 10;
1+
const convertToCelsius = function (fahrenheit) {
2+
return Math.round((fahrenheit - 32) * (5 / 9) * 10) / 10;
33
};
44

5-
const ctof = function (c) {
6-
return Math.round(((c * 9) / 5 + 32) * 10) / 10;
5+
const convertToFahrenheit = function (celsius) {
6+
return Math.round(((celsius * 9) / 5 + 32) * 10) / 10;
77
};
88

99
module.exports = {
10-
ftoc,
11-
ctof,
10+
convertToCelsius,
11+
convertToFahrenheit,
1212
};

0 commit comments

Comments
 (0)