8000 Completed #4 removeFromArray · mikiyabu/javascript-exercises@3e32ac6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3e32ac6

Browse files
committed
Completed TheOdinProject#4 removeFromArray
1 parent 17e4265 commit 3e32ac6

File tree

5 files changed

+41
-26
lines changed
< 8000 button data-component="IconButton" type="button" data-testid="collapse-file-tree-button" aria-expanded="true" aria-controls="diff_file_tree" class="prc-Button-ButtonBase-c50BI d-none d-md-flex position-relative fgColor-muted prc-Button-IconButton-szpyj" data-loading="false" data-no-visuals="true" data-size="medium" data-variant="invisible" aria-describedby=":R72plab:-loading-announcement" aria-labelledby=":R12plab:">

5 files changed

+41
-26
lines changed

02_repeatString/repeatString.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
const repeatString = function(word, num) {
2-
if (num < 0) {
2+
if (num < 0)
33
return 'ERROR';
4-
}
5-
let combinedWord = '';
6-
for(let i = 0; i < num; i++) {
7-
combinedWord += word;
8-
}
9-
return combinedWord;
4+
5+
return word.repeat(num);
106
}
117

128
// Do not edit below this line

04_removeFromArray/removeFromArray.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1-
const removeFromArray = function() {
2-
1+
const removeFromArray = function(...args) {
2+
const arr = args[0];
3+
const newArr = [];
4+
5+
arr.forEach((item) => {
6+
if (!args.includes(item)) {
7+
newArr.push(item);
8+
}
9+
})
10+
return newArr;
311
};
412

13+
514
// Do not edit below this line
615
module.exports = removeFromArray;

04_removeFromArray/removeFromArray.spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ describe('removeFromArray', () => {
44
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
});

package-lock.json

Lines changed: 17 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@
1414
},
1515
"homepage": "https://github.com/TheOdinProject/javascript-exercises#readme",
1616
"devDependencies": {
17-
"jest": "^26.6.3",
18-
"jest-cli": "^26.6.3",
1917
"eslint": "^7.26.0",
2018
"eslint-config-airbnb-base": "^14.2.1",
21-
"eslint-plugin-import": "^2.22.1"
19+
"eslint-plugin-import": "^2.22.1",
20+
"jest": "^26.6.3",
21+
"jest-cli": "^26.6.3"
2222
},
2323
"scripts": {
2424
"test": "jest"
2525
},
2626
"eslintConfig": {
2727
"root": true
2828
},
29-
"jest": {
29+
"jest": {
3030
"testPathIgnorePatterns": [
3131
"generator-exercise/"
3232
]

0 commit comments

Comments
 (0)
0