Passed 2 first tests from exercise 04
This commit is contained in:
parent
bf01232806
commit
553279a58a
|
@ -1,6 +1,18 @@
|
||||||
const removeFromArray = function() {
|
const removeFromArray = function(array, ...remove) {
|
||||||
|
remove.forEach(element => {
|
||||||
|
let findIndexElement = array.findIndex(x => x == element);
|
||||||
|
let saveArray = [];
|
||||||
|
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]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return array;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Do not edit below this line
|
// Do not edit below this line
|
||||||
module.exports = removeFromArray;
|
module.exports = removeFromArray;
|
||||||
|
|
|
@ -4,7 +4,7 @@ describe('removeFromArray', () => {
|
||||||
test('removes a single value', () => {
|
test('removes a single value', () => {
|
||||||
expect(removeFromArray([1, 2, 3, 4], 3)).toEqual([1, 2, 4]);
|
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]);
|
expect(removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]);
|
||||||
});
|
});
|
||||||
test.skip('ignores non present values', () => {
|
test.skip('ignores non present values', () => {
|
||||||
|
|
Loading…
Reference in New Issue