I encountered such a problem at work: given a sorted array (ascending order), delete duplicate data in the array, but only one array can be used, and the size of this array can change.
Example: Array: [1 ,1,2,2,3,3,4,5,7,10]
Output::[1,2,3,4,5,7,10]
Implementation (1):
var arr =new Array(1,1,2,2,3,3,4,5,7,10);
var len = arr.length;
for(var i=len-1; i>=1;i--)
{
if(arr[i-1] == arr[i])
{
arr.splice(i,1);
}
}
alert(arr);
Implementation (2):
var arr =new Array(1,1,2,2,3,3,4,5,7 ,10);var len = arr.length;var k=0;for(var i=1;i