Question about the JavaScript Exercises


#1

Are we encouraged e to write one solution that successfully passes all the tests, or do we write out different solutions that can pass each separate test on their own?

For example these are the tests for the removeFromArray exercises.

Blockquote
describe(‘removeFromArray’, function() {
it(‘removes a single value’, function() {
expect(removeFromArray([1, 2, 3, 4], 3)).toEqual([1, 2, 4]);
});
xit(‘removes multiple values’, function() {
expect(removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]);
});
xit(‘ignores non present values’, function() {
expect(removeFromArray([1, 2, 3, 4], 7, “tacos”)).toEqual([1, 2, 3, 4]);
});
xit(‘ignores non present values, but still works’, function() {
expect(removeFromArray([1, 2, 3, 4], 7, 2)).toEqual([1, 3, 4]);
});
xit(‘can remove all values’, function() {
expect(removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)).toEqual([]);
});
xit(‘works with strings’, function() {
expect(removeFromArray([“hey”, 2, 3, “ho”], “hey”, 3)).toEqual([2, “ho”]);
});
});
Blockquote

Is it possible to write one solution that targets all of these tests or would we have to create multiple different codes to pass each one?


#2

You write one function that makes all the tests pass. This one is tricky for a lot of people to figure out (myself included). I see a lot of people ask questions about this exercise on the Discord channel.


#3

Gotcha. Thank you!