I want to set a time stamp for each number, and then test each numbers timestamp against its self.
var timestamp;
nums=["1", "2", "3"];
nums2=nums.map(myFunction);
function myFunction(num) {
setInterval(function() {
var current_time = Math.floor(Date.now() / 1000);
if (typeof timestamp !== "undefined" ) {
if (current_time > (timestamp + 60)) {
timestamp = Math.floor(Date.now() / 1000);
console.log('time stamp reset');
} else {
console.log('time stamp too young will reset after 60 sec');
}
} else {
timestamp = Math.floor(Date.now() / 1000);
console.log('time stamp set');
}
}, 10000);
}
****If I run script for 20 sec:****
current output:
time stamp set
time stamp too young will reset after 60 sec
time stamp too young will reset after 60 sec
*(10 seconds later)*
time stamp too young will reset after 60 sec
time stamp too young will reset after 60 sec
time stamp too young will reset after 60 sec
desired output:
time stamp set
time stamp set
time stamp set
*(10 seconds later)*
time stamp too young will reset after 60 sec
time stamp too young will reset after 60 sec
time stamp too young will reset after 60 sec
["1"."2"."3"]to[["1",timestamp],["2",timestamp],["3",timestamp]]or perhaps[{"1",timestamp},{"2",timestamp},{"3",timestamp}]mapfunction should only be used to produce a second array of transformed elements. UseforEachto iterate.