const timeline = require('../data/timeline.js'); /** * * @param i * @returns {*} */ function getIndex(i) { if (i >= timeline.length) { return; } return timeline[i]; } /** * @param {number} i - the index. * @returns {{count: number, timestamp: number}|undefined} */ function getNextShot(i) { for (; i < timeline.length; i++) { const time = getIndex(i); for (let event of time.events) { if (event.type === 'shot') { return { timestamp: time.timestamp, count: event.shotCount } } } } return undefined; } function indexForTime(seconds) { let lastIndex = 0; for(let i = 0; i < timeline.length; i++) { const time = timeline[i]; if (time.timestamp >= seconds) { return lastIndex; } lastIndex = i; } } module.exports = { getIndex, getNextShot, indexForTime };