8000 Implemented a function to remove a target value from the array · Andy51011/javascript-exercises@afddb60 · GitHub
[go: up one dir, main page]

Skip to content

Commit afddb60

Browse files
committed
Implemented a function to remove a target value from the array
1 parent 46ec696 commit afddb60

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

removeFromArray/removeFromArray.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
const removeFromArray = function() {
2-
3-
}
1+
const removeFromArray = function(array, ...args) {
2+
3+
let newArray = array.filter(function(item, index) {
4+
if (!args.includes(item)) {
5+
return item;
6+
}
7+
})
8+
return newArray
9+
}
410

511
module.exports = removeFromArray

removeFromArray/removeFromArray.spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ describe('removeFromArray', function() {
44
it('removes a single value', function() {
55
expect(removeFromArray([1, 2, 3, 4], 3)).toEqual([1, 2, 4]);
66
});
7-
xit('removes multiple values', function() {
7+
it('removes multiple values', function() {
88
expect(removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]);
99
});
10-
xit('ignores non present values', function() {
10+
it('ignores non present values', function() {
1111
expect(removeFromArray([1, 2, 3, 4], 7, "tacos")).toEqual([1, 2, 3, 4]);
1212
});
13-
xit('ignores non present values, but still works', function() {
13+
it('ignores non present values, but still works', function() {
1414
expect(removeFromArray([1, 2, 3, 4], 7, 2)).toEqual([1, 3, 4]);
1515
});
16-
xit('can remove all values', function() {
16+
it('can remove all values', function() {
1717
expect(removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)).toEqual([]);
1818
});
19-
xit('works with strings', function() {
19+
it('works with strings', function() {
2020
expect(removeFromArray(["hey", 2, 3, "ho"], "hey", 3)).toEqual([2, "ho"]);
2121
});
22-
xit('only removes same type', function() {
22+
it('only removes same type', function() {
2323
expect(removeFromArray([1, 2, 3], "1", 3)).toEqual([1, 2]);
2424
});
2525
});

0 commit comments

Comments
 (0)
0