Updated exercises

This commit is contained in:
octopusGarden 2022-10-30 12:09:15 -04:00
parent 765dc7031a
commit 353884775e
10 changed files with 61 additions and 38 deletions

View File

@ -10,7 +10,7 @@ This function will take two arguments, `string` and `num`.
*Note:* The exercises after this one will not have arguments provided as this one does - you will need to provide them yourself from now on. So read each exercise's README carefully to see what kinds of arguments will be expected.
You will notice in this exercise that there are multiple tests (see in file `repeatString.spec.js`). Only the first test is currently enabled. So after making sure that this first one passes, enable the others one by one by deleting the `.skip` from the `test.skip()` function.
You will notice in this exercise that there are multiple tests (see in file `repeatString.spec.js`). Only the first test is currently enabled. So after making sure that this first one passes, enable the others one by one by deleting the `` from the `test()` function.
## Hints

View File

@ -1,5 +1,9 @@
const repeatString = function(string, num) {
if (num < 0) {
return "ERROR";
} else {
return string.repeat(num);
}
};
// Do not edit below this line

View File

@ -4,19 +4,19 @@ describe('repeatString', () => {
test('repeats the string', () => {
expect(repeatString('hey', 3)).toEqual('heyheyhey');
});
test.skip('repeats the string many times', () => {
test('repeats the string many times', () => {
expect(repeatString('hey', 10)).toEqual('heyheyheyheyheyheyheyheyheyhey');
});
test.skip('repeats the string 1 times', () => {
test('repeats the string 1 times', () => {
expect(repeatString('hey', 1)).toEqual('hey');
});
test.skip('repeats the string 0 times', () => {
test('repeats the string 0 times', () => {
expect(repeatString('hey', 0)).toEqual('');
});
test.skip('returns ERROR with negative numbers', () => {
test('returns ERROR with negative numbers', () => {
expect(repeatString('hey', -1)).toEqual('ERROR');
});
test.skip('repeats the string a random amount of times', function () {
test('repeats the string a random amount of times', function () {
/*The number is generated by using Math.random to get a value from between
0 to 1, when this is multiplied by 1000 and rounded down with Math.floor it
equals a number between 0 to 999 (this number will change everytime you run
@ -31,7 +31,7 @@ describe('repeatString', () => {
was randomly generated. */
expect(repeatString('hey', number).match(/((hey))/g).length).toEqual(number);
});
test.skip('works with blank strings', () => {
test('works with blank strings', () => {
expect(repeatString('', 10)).toEqual('');
});
});

View File

@ -6,7 +6,7 @@ Pretty simple, write a function called `reverseString` that returns its input, r
reverseString('hello there') // returns 'ereht olleh'
```
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.
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 `` in front the `test()` function.
## Hints
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.

View File

@ -5,14 +5,14 @@ describe('reverseString', () => {
expect(reverseString('hello')).toEqual('olleh');
});
test.skip('reverses multiple words', () => {
test('reverses multiple words', () => {
expect(reverseString('hello there')).toEqual('ereht olleh')
})
test.skip('works with numbers and punctuation', () => {
test('works with numbers and punctuation', () => {
expect(reverseString('123! abc!')).toEqual('!cba !321')
})
test.skip('works with blank strings', () => {
test('works with blank strings', () => {
expect(reverseString('')).toEqual('')
})
});

View File

@ -1,6 +1,6 @@
const removeFromArray = function(list) {
const removeFromArray = function(list, item) {
//Remove third element from array
let remove = list.splice(2, 1);
let remove = list.filter(item);
return list;
};

View File

@ -4,22 +4,22 @@ describe('removeFromArray', () => {
test('removes a single value', () => {
expect(removeFromArray([1, 2, 3, 4], 3)).toEqual([1, 2, 4]);
});
test.skip('removes multiple values', () => {
test('removes multiple values', () => {
expect(removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]);
});
test.skip('ignores non present values', () => {
test('ignores non present values', () => {
expect(removeFromArray([1, 2, 3, 4], 7, "tacos")).toEqual([1, 2, 3, 4]);
});
test.skip('ignores non present values, but still works', () => {
test('ignores non present values, but still works', () => {
expect(removeFromArray([1, 2, 3, 4], 7, 2)).toEqual([1, 3, 4]);
});
test.skip('can remove all values', () => {
test('can remove all values', () => {
expect(removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)).toEqual([]);
});
test.skip('works with strings', () => {
test('works with strings', () => {
expect(removeFromArray(["hey", 2, 3, "ho"], "hey", 3)).toEqual([2, "ho"]);
});
test.skip('only removes same type', () => {
test('only removes same type', () => {
expect(removeFromArray([1, 2, 3], "1", 3)).toEqual([1, 2]);
});
});

View File

@ -1,17 +1,26 @@
const add = function() {
const add = function(num1, num2) {
let total = num1 + num2;
return total;
};
const subtract = function() {
const subtract = function(num1, num2) {
let total = num1 - num2;
return total;
};
const sum = function() {
let total = 0;
for (i = 0; i < numList.length; i++) {
total += parseInt(numList[i]);
}
return total;
};
const multiply = function() {
const multiply = function(num1, num2) {
let total = num1 * num2;
return total;
};
const power = function() {

24
package-lock.json generated
View File

@ -1529,10 +1529,20 @@
}
},
"node_modules/caniuse-lite": {
"version": "1.0.30001223",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001223.tgz",
"integrity": "sha512-k/RYs6zc/fjbxTjaWZemeSmOjO0JJV+KguOBA3NwPup8uzxM1cMhR2BD9XmO86GuqaqTCO8CgkgH9Rz//vdDiA==",
"dev": true
"version": "1.0.30001425",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001425.tgz",
"integrity": "sha512-/pzFv0OmNG6W0ym80P3NtapU0QEiDS3VuYAZMGoLLqiC7f6FJFe1MjpQDREGApeenD9wloeytmVDj+JLXPC6qw==",
"dev": true,
"funding": [
{
"type": "opencollective",
"url": "https://opencollective.com/browserslist"
},
{
"type": "tidelift",
"url": "https://tidelift.com/funding/github/npm/caniuse-lite"
}
]
},
"node_modules/capture-exit": {
"version": "2.0.0",
@ -8739,9 +8749,9 @@
"dev": true
},
"caniuse-lite": {
"version": "1.0.30001223",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001223.tgz",
"integrity": "sha512-k/RYs6zc/fjbxTjaWZemeSmOjO0JJV+KguOBA3NwPup8uzxM1cMhR2BD9XmO86GuqaqTCO8CgkgH9Rz//vdDiA==",
"version": "1.0.30001425",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001425.tgz",
"integrity": "sha512-/pzFv0OmNG6W0ym80P3NtapU0QEiDS3VuYAZMGoLLqiC7f6FJFe1MjpQDREGApeenD9wloeytmVDj+JLXPC6qw==",
"dev": true
},
"capture-exit": {

View File

@ -14,11 +14,11 @@
},
"homepage": "https://github.com/TheOdinProject/javascript-exercises#readme",
"devDependencies": {
"jest": "^26.6.3",
"jest-cli": "^26.6.3",
"eslint": "^7.26.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.22.1"
"eslint-plugin-import": "^2.22.1",
"jest": "^26.6.3",
"jest-cli": "^26.6.3"
},
"scripts": {
"test": "jest"