Easy to understand for beginners as well(commented)
\nvar findPoisonedDuration = function(timeSeries, duration) {\n  let count=0;\n    for(let i=0;i<timeSeries.length;i++){\n\t// if the time interval between 2 co
```\nvar findPoisonedDuration = function(timeSeries, duration) {\n  let count=0;\n    for(let i=0;i<timeSeries.length;i++){\n\t// if the time interval between 2 consecutive attacks is within the duration, then only within that period of time the person would be poisoined\n        if(timeSeries[i+1] && timeSeries[i+1]-timeSeries[i]<duration){\n            count+=timeSeries[i+1]-timeSeries[i]\n        }else{\n\t\t// if not person would be poisoined for the entire duration\n            count+=duration;\n        }\n    }\n    return count;\n};\n```\nRuntime: 72 ms, faster than 98.78% of JavaScript online submissions for Teemo Attacking.\nMemory Usage: 42.7 MB, less than 57.32% of JavaScript online submissions for Teemo Attacking.
['JavaScript']