Skip to content

Commit 614b8b8

Browse files
authored
Merge branch 'main' into fix_typo_readme
2 parents 84d537f + 75869d1 commit 614b8b8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+754
-11
lines changed

.circleci/config.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: 2.1
2+
3+
orbs:
4+
node: circleci/[email protected]
5+
6+
jobs:
7+
test-solutions:
8+
executor: node/default
9+
steps:
10+
- checkout
11+
- node/install-packages:
12+
pkg-manager: npm
13+
- run:
14+
command: npm run test solution
15+
name: Run tests in **/solution/*.spec.js
16+
17+
workflows:
18+
test-solutions:
19+
jobs:
20+
- test-solutions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const helloWorld = function () {
2+
return "Hello, World!";
3+
};
4+
5+
module.exports = helloWorld;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const helloWorld = require('./helloWorld-solution');
2+
3+
describe('Hello World', function () {
4+
test('says "Hello, World!"', function () {
5+
expect(helloWorld()).toEqual('Hello, World!');
6+
});
7+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
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;
8+
};
9+
10+
module.exports = repeatString;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const repeatString = require('./repeatString-solution');
2+
3+
describe('repeatString', () => {
4+
test('repeats the string', () => {
5+
expect(repeatString('hey', 3)).toEqual('heyheyhey');
6+
});
7+
test('repeats the string many times', () => {
8+
expect(repeatString('hey', 10)).toEqual('heyheyheyheyheyheyheyheyheyhey');
9+
});
10+
test('repeats the string 1 times', () => {
11+
expect(repeatString('hey', 1)).toEqual('hey');
12+
});
13+
test('repeats the string 0 times', () => {
14+
expect(repeatString('hey', 0)).toEqual('');
15+
});
16+
test('returns ERROR with negative numbers', () => {
17+
expect(repeatString('hey', -1)).toEqual('ERROR');
18+
});
19+
test('repeats the string a random amount of times', function () {
20+
/*The number is generated by using Math.random to get a value from between
21+
0 to 1, when this is multiplied by 1000 and rounded down with Math.floor it
22+
equals a number between 0 to 999 (this number will change everytime you run
23+
the test).*/
24+
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
30+
in the result, which if your function works correctly will equal the number that
31+
was randomaly generated. */
32+
expect(repeatString('hey', number).match(/((hey))/g).length).toEqual(
33+
number
34+
);
35+
});
36+
test('works with blank strings', () => {
37+
expect(repeatString('', 10)).toEqual('');
38+
});
39+
});

03_reverseString/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,5 @@ Pretty simple, write a function called `reverseString` that returns its input, r
66
reverseString('hello there') // returns 'ereht olleh'
77
```
88

9-
You will notice in this exercise that there are multiple tests, after making the first one pass, enable the others one by one by deleting the `.skip` in front the `test.skip()` function.
10-
119
## Hints
1210
Strings in JavaScript cannot be reversed directly so you're going to have to split it into something else first.. do the reversal and then join it back together into a string.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const reverseString = function (string) {
2+
return string.split("").reverse().join("");
3+
};
4+
5+
module.exports = reverseString;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const reverseString = require('./reverseString-solution');
2+
3+
describe('reverseString', () => {
4+
test('reverses single word', () => {
5+
expect(reverseString('hello')).toEqual('olleh');
6+
});
7+
8+
test('reverses multiple words', () => {
9+
expect(reverseString('hello there')).toEqual('ereht olleh');
10+
});
11+
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+
});
18+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// we have 2 solutions here, an easier one and a more advanced one.
2+
// The easiest way to get an array of the rest of the arguments that are passed to a function
3+
// is using the rest operator. If this is unfamiliar to you look it up!
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;
18+
};
19+
20+
// A simpler, but more advanced way to do it is to use the 'filter' function,
21+
// which basically does what we did with the forEach above.
22+
23+
// var removeFromArray = function(array, ...args) {
24+
// return array.filter(val => !args.includes(val))
25+
// }
26+
//
27+
28+
module.exports = removeFromArray;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const removeFromArray = require('./removeFromArray-solution');
2+
3+
describe('removeFromArray', () => {
4+
test('removes a single value', () => {
5+
expect(removeFromArray([1, 2, 3, 4], 3)).toEqual([1, 2, 4]);
6+
});
7+
test('removes multiple values', () => {
8+
expect(removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]);
9+
});
10+
test('ignores non present values', () => {
11+
expect(removeFromArray([1, 2, 3, 4], 7, 'tacos')).toEqual([1, 2, 3, 4]);
12+
});
13+
test('ignores non present values, but still works', () => {
14+
expect(removeFromArray([1, 2, 3, 4], 7, 2)).toEqual([1, 3, 4]);
15+
});
16+
test('can remove all values', () => {
17+
expect(removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)).toEqual([]);
18+
});
19+
test('works with strings', () => {
20+
expect(removeFromArray(['hey', 2, 3, 'ho'], 'hey', 3)).toEqual([2, 'ho']);
21+
});
22+
test('only removes same type', () => {
23+
expect(removeFromArray([1, 2, 3], '1', 3)).toEqual([1, 2]);
24+
});
25+
});

0 commit comments

Comments
 (0)