Я хочу установить отметку времени для каждого числа, а затем проверить каждую отметку времени чисел по отношению к самому себе.
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);
}
**** Если я запускаю скрипт в течение 20 секунд: ****
токовый выход:
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
желаемый результат:
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