Skip to content

Commit

Permalink
Add strict equality and pass all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
worriedape committed Dec 10, 2024
1 parent 02d3f0d commit 80b0615
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
5 changes: 4 additions & 1 deletion 04_removeFromArray/removeFromArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const removeFromArray = (array, ...deletable) => {

outer: for (let x of array) {
for (let item of deletable) {
if (x == item) continue outer;
if (x === item) continue outer;
}
newArray.push(x);
}
Expand All @@ -27,4 +27,7 @@ module.exports = removeFromArray;
removeFromArray([1,2,3], 2)
From given solution:
**let newArray = array.filter(x => !deletable.includes(x));
*/
14 changes: 7 additions & 7 deletions 04_removeFromArray/removeFromArray.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ 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('removes multiple of the same value', () => {
test('removes multiple of the same value', () => {
expect(removeFromArray([1, 2, 2, 3], 2)).toEqual([1, 3]);
});
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]);
});
});

0 comments on commit 80b0615

Please sign in to comment.