8000 Completed exercise #04 · ZBO-R8io/javascript-exercises@f879390 · GitHub
[go: up one dir, main page]

Skip to content

Commit f879390

Browse files
committed
Completed exercise TheOdinProject#4
1 parent 2c42b22 commit f879390

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

04_removeFromArray/removeFromArray.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
1-
const removeFromArray = function() {
1+
const removeFromArray = function(array, ...args) {
2+
const newArray = [];
3+
array.forEach((item) => {
4+
if (!args.includes(item)) {
5+
newArray.push(item);
6+
};
7+
});
8+
return newArray;
29
};
310

11+
removeFromArray([1, 2, 3, 4], 3);
12+
13+
removeFromArray([1, 2, 3, 4], 3, 2);
14+
15+
removeFromArray([1, 2, 2, 3], 2);
16+
17+
removeFromArray([1, 2, 3, 4], 7, "tacos");
18+
19+
removeFromArray([1, 2, 3, 4], 7, 2);
20+
21+
removeFromArray([1, 2, 3, 4], 1, 2, 3, 4);
22+
23+
removeFromArray(["hey", 2, 3, "ho"], "hey", 3);
24+
25+
removeFromArray([1, 2, 3], "1", 3);
26+
427
// Do not edit below this line
528
module.exports = removeFromArray;

04_removeFromArray/removeFromArray.spec.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@ 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('removes multiple of the same value', () => {
10+
test('removes multiple of the same value', () => {
1111
expect(removeFromArray([1, 2, 2, 3], 2)).toEqual([1, 3]);
1212
});
13-
test.skip('ignores non present values', () => {
13+
test('ignores non present values', () => {
1414
expect(removeFromArray([1, 2, 3, 4], 7, "tacos")).toEqual([1, 2, 3, 4]);
1515
});
16-
test.skip('ignores non present values, but still works', () => {
16+
test('ignores non present values, but still works', () => {
1717
expect(removeFromArray([1, 2, 3, 4], 7, 2)).toEqual([1, 3, 4]);
1818
});
19-
test.skip('can remove all values', () => {
19+
test('can remove all values', () => {
2020
expect(removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)).toEqual([]);
2121
});
22-
test.skip('works with strings', () => {
22+
test('works with strings', () => {
2323
expect(removeFromArray(["hey", 2, 3, "ho"], "hey", 3)).toEqual([2, "ho"]);
2424
});
25-
test.skip('only removes same type', () => {
25+
test('only removes same type', () => {
2626
expect(removeFromArray([1, 2, 3], "1", 3)).toEqual([1, 2]);
2727
});
2828
});

0 commit comments

Comments
 (0)
0