- Implement function
removeElement(array, item)to delete elementitemfromarray. Example:
const array = [1, 2, 3, 4, 5, 6, 7];
removeElement(array, 5);
console.log(array);
// Result: [1, 2, 3, 4, 6, 7]or
const array = ['Kiev', 'Beijing', 'Lima', 'Saratov'];
removeElement(array, 'Lima'); // remove 'Lima' from array
removeElement(array, 'Berlin'); // do nothing
console.log(array);
// Result: ['Kiev', 'Beijing', 'Saratov']- Improve previous task function for removing multiple elements from
array
removeElements(array, item1, ... itemN). Example:
const array = [1, 2, 3, 4, 5, 6, 7];
removeElements(array, 5, 1, 6);
console.log(array);
// Result: [2, 3, 4, 7]or
const array = ['Kiev', 'Beijing', 'Lima', 'Saratov'];
removeElements(array, 'Lima', 'Berlin', 'Kiev');
console.log(array);
// Result: ['Beijing', 'Saratov']- Function
unique(array)should return new array, not containing duplicates. Call example:
const result = unique([2, 1, 1, 3, 2]);
console.log(result);
// Result: [2, 1, 3]const result = unique(['top', 'bottom', 'top', 'left']);
console.log(result);
// Result: ['top', 'bottom', 'left']- Function
difference(array1, array2)should find difference between array and return new array containing elements fromarray1but not containing inarray2. Call example:
const array1 = [7, -2, 10, 5, 0];
const array2 = [0, 10];
const result = difference(array1, array2);
console.log(result);
// Result: [7, -2, 5]const array1 = ['Beijing', 'Kiev'];
const array2 = ['Kiev', 'London', 'Baghdad'];
const result = difference(array1, array2);
console.log(result);
// Result: ['Beijing']