Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const messages = {
- '0000': 'Message at 0 minute of stream time',
- '0520': 'eillax is live 0520',
- '0523': 'eillax is live 0523',
- '0535': 'eillax is live 0535',
- '0540': 'eillax is live 0540'
- };
- const messagesTimestamps = Object.keys(messages);
- const findData = (string, regex) => string.match(regex) || '0';
- const keepAmount = string => string.split(' ').filter(e => isNaN(e) === false);
- const normalizeAmount = string => string.padStart(2, '0');
- const arrayToString = array => Array.isArray(array) ? array.join('') : array;
- const hourRegex = /\d+\s\bhour/;
- const minuteRegex = /\d+\s\bminute/;
- const hourData = arrayToString(findData(uptime, hourRegex));
- const minuteData = arrayToString(findData(uptime, minuteRegex));
- const hourAmount = arrayToString(keepAmount(hourData));
- const minuteAmount = arrayToString(keepAmount(minuteData));
- const normalizedHourAmount = normalizeAmount(hourAmount);
- const normalizedMinuteAmount = normalizeAmount(minuteAmount);
- const currentTime = normalizedHourAmount.concat(normalizedMinuteAmount);
- let timestamp = [];
- messagesTimestamps.forEach(e => {
- if (Math.abs(parseInt(e) - parseInt(currentTime)) <= 5) {
- timestamp.push(e);
- }
- });
- messages[timestamp[0]] || ' ';
Add Comment
Please, Sign In to add comment