Skip to content

Commit 6d435a7

Browse files
Resolve till 3rd exercise inclusive
1 parent 8746ce0 commit 6d435a7

File tree

6 files changed

+7533
-41
lines changed

6 files changed

+7533
-41
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: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
const repeatString = function() {
2-
1+
const repeatString = function (string, num) {
2+
if (num < 0) return "ERROR";
3+
let resultString = "";
4+
for (let i = 0; i < num; i++) {
5+
resultString += string;
6+
}
7+
return resultString;
38
};
49

510
// Do not edit below this line
Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,39 @@
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(
33+
number
34+
);
3335
});
34-
test.skip('works with blank strings', () => {
35-
expect(repeatString('', 10)).toEqual('');
36+
test("works with blank strings", () => {
37+
expect(repeatString("", 10)).toEqual("");
3638
});
3739
});

03_reverseString/reverseString.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const reverseString = function() {
2-
1+
const reverseString = function (string) {
2+
return string.split("").reverse().join("");
33
};
44

55
// 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
});

0 commit comments

Comments
 (0)