Passed fifth and sixth test from exercise 04

This commit is contained in:
NetMan 2024-01-05 21:33:43 +01:00
parent f0c8df6081
commit 1d72ec8b14
2 changed files with 3 additions and 5 deletions

View File

@ -3,7 +3,7 @@ const removeFromArray = function(array, ...remove) {
let findIndexElement = array.findIndex(x => x == element); let findIndexElement = array.findIndex(x => x == element);
if (findIndexElement >= 0) { if (findIndexElement >= 0) {
let saveArray = []; let saveArray = [];
for (let i = 0; i < array.length - findIndexElement; i++) { for (let i = 0, arrayLength = array.length; i < arrayLength - findIndexElement - 1; i++) {
saveArray.push(array.pop()); saveArray.push(array.pop());
} }
array.pop(); array.pop();
@ -15,7 +15,5 @@ const removeFromArray = function(array, ...remove) {
return array; return array;
}; };
removeFromArray([1, 2, 3, 4], 7, 2);
// Do not edit below this line // Do not edit below this line
module.exports = removeFromArray; module.exports = removeFromArray;

View File

@ -13,10 +13,10 @@ describe('removeFromArray', () => {
test('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]); 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([]); 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"]); expect(removeFromArray(["hey", 2, 3, "ho"], "hey", 3)).toEqual([2, "ho"]);
}); });
test.skip('only removes same type', () => { test.skip('only removes same type', () => {