Passed the third test from exercise 04
This commit is contained in:
parent
553279a58a
commit
2d6400b9bb
|
@ -1,14 +1,16 @@
|
||||||
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);
|
||||||
let saveArray = [];
|
if (findIndexElement >= 0) {
|
||||||
for (let i = 0; i < array.length - findIndexElement; i++) {
|
let saveArray = [];
|
||||||
saveArray.push(array.pop());
|
for (let i = 0; i < array.length - findIndexElement; i++) {
|
||||||
|
saveArray.push(array.pop());
|
||||||
|
}
|
||||||
|
array.pop();
|
||||||
|
for (let i = 0; i < saveArray.length; i++) {
|
||||||
|
array.push(saveArray[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
array.pop();
|
|
||||||
for (let i = 0; i < saveArray.length; i++) {
|
|
||||||
array.push(saveArray[i]);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return array;
|
return array;
|
||||||
};
|
};
|
||||||
|
|
|
@ -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', () => {
|
||||||
|
|
Loading…
Reference in New Issue