Skip to content

Commit 7ab43a5

Browse files
committed
Initial commit
1 parent c1a8e72 commit 7ab43a5

File tree

13 files changed

+7606
-95
lines changed

13 files changed

+7606
-95
lines changed

01_helloWorld/helloWorld.js

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

55
module.exports = helloWorld;

02_repeatString/repeatString.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
const repeatString = function() {
1+
const repeatString = function (string, num) {
2+
if (num < 0) return "ERROR";
23

4+
let result = "";
5+
for (let i = 0; i < num; i++) {
6+
result += string;
7+
}
8+
9+
return result;
310
};
411

512
// Do not edit below this line

02_repeatString/repeatString.spec.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
const repeatString = require('./repeatString')
1+
const repeatString = require("./repeatString");
22

3-
describe('repeatString', () => {
4-
test('repeats the string', () => {
5-
expect(repeatString('hey', 3)).toEqual('heyheyhey');
3+
describe("repeatString", () => {
4+
test("repeats the string", () => {
5+
expect(repeatString("hey", 3)).toEqual("heyheyhey");
66
});
7-
test.skip('repeats the string many times', () => {
8-
expect(repeatString('hey', 10)).toEqual('heyheyheyheyheyheyheyheyheyhey');
7+
test("repeats the string many times", () => {
8+
expect(repeatString("hey", 10)).toEqual("heyheyheyheyheyheyheyheyheyhey");
99
});
10-
test.skip('repeats the string 1 times', () => {
11-
expect(repeatString('hey', 1)).toEqual('hey');
10+
test("repeats the string 1 times", () => {
11+
expect(repeatString("hey", 1)).toEqual("hey");
1212
});
13-
test.skip('repeats the string 0 times', () => {
14-
expect(repeatString('hey', 0)).toEqual('');
13+
test("repeats the string 0 times", () => {
14+
expect(repeatString("hey", 0)).toEqual("");
1515
});
16-
test.skip('returns ERROR with negative numbers', () => {
17-
expect(repeatString('hey', -1)).toEqual('ERROR');
16+
test("returns ERROR with negative numbers", () => {
17+
expect(repeatString("hey", -1)).toEqual("ERROR");
1818
});
19-
test.skip('repeats the string a random amount of times', function () {
19+
test("repeats the string a random amount of times", function () {
2020
/*The number is generated by using Math.random to get a value from between
2121
0 to 1, when this is multiplied by 1000 and rounded down with Math.floor it
2222
equals a number between 0 to 999 (this number will change everytime you run
2323
the test).*/
2424

25-
// DO NOT use Math.floor(Math.random() * 1000) in your code,
25+
// DO NOT use Math.floor(Math.random() * 1000) in your code,
2626
// this test generates a random number, then passes it into your code with a function parameter.
2727
// 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)
28+
const number = Math.floor(Math.random() * 1000);
2929
/*The .match(/((hey))/g).length is a regex that will count the number of heys
3030
in the result, which if your function works correctly will equal the number that
3131
was randomly generated. */
32-
expect(repeatString('hey', number).match(/((hey))/g).length).toEqual(number);
32+
expect(repeatString("hey", number).match(/((hey))/g).length).toEqual(number);
3333
});
34-
test.skip('works with blank strings', () => {
35-
expect(repeatString('', 10)).toEqual('');
34+
test("works with blank strings", () => {
35+
expect(repeatString("", 10)).toEqual("");
3636
});
3737
});

03_reverseString/reverseString.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
const reverseString = function(str) {
1+
const reverseString = function (str) {
2+
letters = str.split("");
3+
result = "";
24

5+
for (let i = letters.length - 1; i >= 0; i--) {
6+
result += letters[i];
7+
}
8+
return result;
39
};
410

511
// Do not edit below this line
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
const reverseString = require('./reverseString')
1+
const reverseString = require("./reverseString");
22

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

8-
test.skip('reverses multiple words', () => {
9-
expect(reverseString('hello there')).toEqual('ereht olleh')
10-
})
8+
test("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("works with numbers and punctuation", () => {
13+
expect(reverseString("123! abc!")).toEqual("!cba !321");
14+
});
15+
test("works with blank strings", () => {
16+
expect(reverseString("")).toEqual("");
17+
});
1818
});

04_removeFromArray/removeFromArray.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const removeFromArray = function() {
2-
1+
const removeFromArray = function (arr, ...targets) {
2+
return arr.filter((val) => !targets.includes(val));
33
};
44

55
// Do not edit below this line
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
const removeFromArray = require('./removeFromArray')
1+
const removeFromArray = require("./removeFromArray");
22

3-
describe('removeFromArray', () => {
4-
test('removes a single value', () => {
3+
describe("removeFromArray", () => {
4+
test("removes a single value", () => {
55
expect(removeFromArray([1, 2, 3, 4], 3)).toEqual([1, 2, 4]);
66
});
7-
test.skip('removes multiple values', () => {
7+
test("removes multiple values", () => {
88
expect(removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]);
99
});
10-
test.skip('ignores non present values', () => {
10+
test("ignores non present values", () => {
1111
expect(removeFromArray([1, 2, 3, 4], 7, "tacos")).toEqual([1, 2, 3, 4]);
1212
});
13-
test.skip('ignores non present values, but still works', () => {
13+
test("ignores non present values, but still works", () => {
1414
expect(removeFromArray([1, 2, 3, 4], 7, 2)).toEqual([1, 3, 4]);
1515
});
16-
test.skip('can remove all values', () => {
16+
test("can remove all values", () => {
1717
expect(removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)).toEqual([]);
1818
});
19-
test.skip('works with strings', () => {
19+
test("works with strings", () => {
2020
expect(removeFromArray(["hey", 2, 3, "ho"], "hey", 3)).toEqual([2, "ho"]);
2121
});
22-
test.skip('only removes same type', () => {
22+
test("only removes same type", () => {
2323
expect(removeFromArray([1, 2, 3], "1", 3)).toEqual([1, 2]);
2424
});
2525
});

05_sumAll/sumAll.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
const sumAll = function() {
1+
const sumAll = function (start, end) {
2+
if (start < 0 || end < 0) return "ERROR";
3+
if (!Number.isInteger(start) || !Number.isInteger(end)) return "ERROR";
4+
if (start > end) [start, end] = [end, start];
25

6+
let sum = 0;
7+
8+
for (let i = start; i <= end; i++) {
9+
sum += i;
10+
}
11+
12+
return sum;
313
};
414

515
// Do not edit below this line

05_sumAll/sumAll.spec.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
const sumAll = require('./sumAll')
1+
const sumAll = require("./sumAll");
22

3-
describe('sumAll', () => {
4-
test('sums numbers within the range', () => {
3+
describe("sumAll", () => {
4+
test("sums numbers within the range", () => {
55
expect(sumAll(1, 4)).toEqual(10);
66
});
7-
test.skip('works with large numbers', () => {
7+
test("works with large numbers", () => {
88
expect(sumAll(1, 4000)).toEqual(8002000);
99
});
10-
test.skip('works with larger number first', () => {
10+
test("works with larger number first", () => {
1111
expect(sumAll(123, 1)).toEqual(7626);
1212
});
13-
test.skip('returns ERROR with negative numbers', () => {
14-
expect(sumAll(-10, 4)).toEqual('ERROR');
13+
test("returns ERROR with negative numbers", () => {
14+
expect(sumAll(-10, 4)).toEqual("ERROR");
1515
});
16-
test.skip('returns ERROR with non-number parameters', () => {
17-
expect(sumAll(10, "90")).toEqual('ERROR');
16+
test("returns ERROR with non-number parameters", () => {
17+
expect(sumAll(10, "90")).toEqual("ERROR");
1818
});
19-
test.skip('returns ERROR with non-number parameters', () => {
20-
expect(sumAll(10, [90, 1])).toEqual('ERROR');
19+
test("returns ERROR with non-number parameters", () => {
20+
expect(sumAll(10, [90, 1])).toEqual("ERROR");
2121
});
2222
});

06_leapYears/leapYears.js

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

55
// Do not edit below this line

0 commit comments

Comments
 (0)