Completed exercises 04 and 05
This commit is contained in:
		
							parent
							
								
									0c4553b3b7
								
							
						
					
					
						commit
						e974761c99
					
				|  | @ -1,5 +1,13 @@ | |||
| const removeFromArray = function() { | ||||
| const removeFromArray = function(arr, ...args) { | ||||
|     const newArr = []; | ||||
| 
 | ||||
|     arr.forEach((item) => { | ||||
|         if(!args.includes(item)) { | ||||
|             newArr.push(item); | ||||
|         } | ||||
|     }); | ||||
| 
 | ||||
|     return newArr; | ||||
| }; | ||||
| 
 | ||||
| // Do not edit below this line
 | ||||
|  |  | |||
|  | @ -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]); | ||||
|   }); | ||||
| }); | ||||
|  |  | |||
|  | @ -1,5 +1,19 @@ | |||
| const sumAll = function() { | ||||
| const sumAll = function(num1, num2) { | ||||
|     let sum = 0; | ||||
|     const arr = []; | ||||
| 
 | ||||
|     if(!Number.isInteger(num1) || !Number.isInteger(num2)) return 'ERROR'; | ||||
|     if(num1 < 0 || num2 < 0) return 'ERROR'; | ||||
| 
 | ||||
|     for(let i = 1; i <= Math.max(num1, num2); i++) { | ||||
|         arr.push(i); | ||||
|     } | ||||
| 
 | ||||
|     arr.forEach(num => { | ||||
|         sum += num; | ||||
|     }) | ||||
| 
 | ||||
|     return sum; | ||||
| }; | ||||
| 
 | ||||
| // Do not edit below this line
 | ||||
|  |  | |||
|  | @ -4,19 +4,19 @@ describe('sumAll', () => { | |||
|   test('sums numbers within the range', () => { | ||||
|     expect(sumAll(1, 4)).toEqual(10); | ||||
|   }); | ||||
|   test.skip('works with large numbers', () => { | ||||
|   test('works with large numbers', () => { | ||||
|     expect(sumAll(1, 4000)).toEqual(8002000); | ||||
|   }); | ||||
|   test.skip('works with larger number first', () => { | ||||
|   test('works with larger number first', () => { | ||||
|     expect(sumAll(123, 1)).toEqual(7626); | ||||
|   }); | ||||
|   test.skip('returns ERROR with negative numbers', () => { | ||||
|   test('returns ERROR with negative numbers', () => { | ||||
|     expect(sumAll(-10, 4)).toEqual('ERROR'); | ||||
|   }); | ||||
|   test.skip('returns ERROR with non-number parameters', () => { | ||||
|   test('returns ERROR with non-number parameters', () => { | ||||
|     expect(sumAll(10, "90")).toEqual('ERROR'); | ||||
|   }); | ||||
|   test.skip('returns ERROR with non-number parameters', () => { | ||||
|   test('returns ERROR with non-number parameters', () => { | ||||
|     expect(sumAll(10, [90, 1])).toEqual('ERROR'); | ||||
|   }); | ||||
| }); | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue