arr1 is an array of integers. arr2 contains the list of indexes of elements that I wish to remove from arr1.
So this my JS function:
function deletion()
{
var arr3=[];
var arr1= [2,3,4,5,6,7,8,11,22];
console.log(arr1);
var arr2 = [4,0,1];
for(var i=0;i<arr2.length;i++)
{
arr3.push(arr1[arr2[i]]);
}
for(var j=0;j<arr3.length;j++)
{
arr1.splice(arr1.indexOf(arr3[j]),1);
}
console.log(arr1,"array1");
}
This works fine but now the requirement is : I need to use more efficient way . arr3 should not be used i.e I don't want to use another new array and push elements into it and then loop through it.I want this to be achieved without using new array.
Is there a way to achieve this??and no library should be used,this must be done through Java Script only.
Apologies if the question is ridiculous.. This is for an assignment that I must complete.
arr2in descending order and then splicearr1directly.