Passed the third test from exercise 04

This commit is contained in:
NetMan 2024-01-05 21:22:30 +01:00
parent 553279a58a
commit 2d6400b9bb
2 changed files with 10 additions and 8 deletions

View File

@ -1,6 +1,7 @@
const removeFromArray = function(array, ...remove) { const removeFromArray = function(array, ...remove) {
remove.forEach(element => { remove.forEach(element => {
let findIndexElement = array.findIndex(x => x == element); let findIndexElement = array.findIndex(x => x == element);
if (findIndexElement >= 0) {
let saveArray = []; let saveArray = [];
for (let i = 0; i < array.length - findIndexElement; i++) { for (let i = 0; i < array.length - findIndexElement; i++) {
saveArray.push(array.pop()); saveArray.push(array.pop());
@ -9,6 +10,7 @@ const removeFromArray = function(array, ...remove) {
for (let i = 0; i < saveArray.length; i++) { for (let i = 0; i < saveArray.length; i++) {
array.push(saveArray[i]); array.push(saveArray[i]);
} }
}
}); });
return array; return array;
}; };

View File

@ -7,7 +7,7 @@ describe('removeFromArray', () => {
test('removes multiple values', () => { test('removes multiple values', () => {
expect(removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]); expect(removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]);
}); });
test.skip('ignores non present values', () => { test('ignores non present values', () => {
expect(removeFromArray([1, 2, 3, 4], 7, "tacos")).toEqual([1, 2, 3, 4]); expect(removeFromArray([1, 2, 3, 4], 7, "tacos")).toEqual([1, 2, 3, 4]);
}); });
test.skip('ignores non present values, but still works', () => { test.skip('ignores non present values, but still works', () => {