Passed fifth and sixth test from exercise 04
This commit is contained in:
parent
f0c8df6081
commit
1d72ec8b14
|
@ -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;
|
||||||
|
|
|
@ -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', () => {
|
||||||
|
|
Loading…
Reference in New Issue