Created code to remove two values
This commit is contained in:
		
							parent
							
								
									3699f94da9
								
							
						
					
					
						commit
						4250c06303
					
				| 
						 | 
				
			
			@ -1,8 +1,10 @@
 | 
			
		|||
const removeFromArray = function(...args) {
 | 
			
		||||
 | 
			
		||||
    let myArray = args[0];
 | 
			
		||||
    let pos = 0;
 | 
			
		||||
 | 
			
		||||
    let myArray = args[0]; //Create an array with the first function argument
 | 
			
		||||
    let pos = 0; //Create a variable to store index of element
 | 
			
		||||
 | 
			
		||||
    // Remove all the remaining elements from the array 
 | 
			
		||||
    for (let i = 1; i < args.length; i++) {
 | 
			
		||||
        pos = myArray.indexOf(args[i]);
 | 
			
		||||
        myArray.splice(pos, 1);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,7 +4,7 @@ describe('removeFromArray', function() {
 | 
			
		|||
    it('removes a single value', function() {
 | 
			
		||||
        expect(removeFromArray([1, 2, 3, 4], 3)).toEqual([1, 2, 4]);
 | 
			
		||||
    });
 | 
			
		||||
    xit('removes multiple values', function() {
 | 
			
		||||
    it('removes multiple values', function() {
 | 
			
		||||
        expect(removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]);
 | 
			
		||||
    });
 | 
			
		||||
    xit('ignores non present values', function() {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue