Add files via upload

This commit is contained in:
reddforman 2022-11-09 06:26:20 -08:00 committed by GitHub
parent d6682bdb72
commit 2564a335bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 14 deletions

View File

@ -1,20 +1,20 @@
/*
const removeFromArray = function(array, number, ...moreNumber) {
const removeFromArray = function(array, number) {
const index = array.indexOf(number);
const removeArray = array.splice(index, 1);
array.splice(index, 1);
return array;
};
*/
const removeFromArray = function(array, ...moreNumber) {
for (let i = 0; i <= moreNumber.length; i++) {
const index = array.indexOf(moreNumber);
newArray = array.splice(index, 1);
for (let i = 0; i < moreNumber.length; i++) {
const index = array.indexOf(moreNumber[i]);
if (index >= 0) {
array.splice(index, 1);
}
}
return array;
return array
};

View File

@ -4,22 +4,22 @@ describe('removeFromArray', () => {
test('removes a single value', () => {
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]);
});
test.skip('ignores non present values', () => {
test('ignores non present values', () => {
expect(removeFromArray([1, 2, 3, 4], 7, "tacos")).toEqual([1, 2, 3, 4]);
});
test.skip('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]);
});
test.skip('can remove all values', () => {
test('can remove all values', () => {
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"]);
});
test.skip('only removes same type', () => {
test('only removes same type', () => {
expect(removeFromArray([1, 2, 3], "1", 3)).toEqual([1, 2]);
});
});