The array looks like:
var test = [
{
Time: new Date(1000),
psi:100.0
},
{
Time: new Date(1000),
psi:200.0
},
{
Time: new Date(2000),
psi:200.0
}
]
The function looks like (the function was copied from some online resource, couldn't find the exact reference.)
function uniqTimetable(nums){
console.log(nums); //log#1
var length = nums.length;
var count = 0;
for (var i =0; i< length-1; i++){
if (nums[count].Time.getTime() !== nums[i+1].Time.getTime()){
count ++;
nums[count] = nums[i+1];
}
}
nums.length = count + 1;
console.log(nums); // log #2
}
uniqTimetable(test);
console.log(test);// log #3
Are there any problems of
copy one object to the other array member by this line
nums[count] = nums[i+1]rescale the array length by this line
nums.length = count + 1?
With electron/node.js, the output looks a bit weird.
In log#1, it shows the array length is 2 instead of 3. Something seems wrong with the function. Any suggestions welcome.
Thanks in advance.
nodejsare you using?12.13.0), but it shows correct about the length oftest.