I'm trying to make a transcript command, and it will store the channel's messages and recreate it into an HTML page, but the way that I sorted it isn't working. here is what I have so far
let msgs = totalMessages
let sorted = []
for (let i = 0; msgs.length; i++) {
let msgGroup = [msgs[0]]
for (let a in msgs) {
if (msgs[a].time <= first.time + 5 && msgs[a].name == first.name) msgGroup.push(msgs[a])
else break
}
msgs = msgs.slice(msgGroup.length)
sorted[i] = msgGroup
}
Here's an example of what the total messages would look like:
let messages = [{'name': 'user1', 'time': '5:00pm'},
{'name': 'user1', 'time': '5:01pm'},
{'name': 'user1', 'time': '5:09pm'},
{'name': 'user2', 'time': '5:11pm'},
{'name': 'user2', 'time': '5:12pm'},
{'name': 'user1', 'time': '5:13pm'},
{'name': 'user2', 'time': '5:14pm'},
{'name': 'user2', 'time': '5:15pm'},
{'name': 'user2', 'time': '5:25pm'}]
Here is what I expect the output to be
[[{'name': 'user1', 'time': '5:00pm'},
{'name': 'user1', 'time': '5:01pm'}],
[{'name': 'user1', 'time': '5:09pm'}],
[{'name': 'user2', 'time': '5:11pm'},
{'name': 'user2', 'time': '5:12pm'},],
[{'name': 'user1', 'time': '5:13pm'}],
[{'name': 'user2', 'time': '5:14pm'},
{'name': 'user2', 'time': '5:15pm'}],
[{'name': 'user2', 'time': '5:25pm'}]
]
the way I did it, was the first message will be put in a group, and if the next message is not 10 minutes older than the first message, and the message authors are the same, add it to the group, if not, create a new message group with that message and remove messages in groups from the original array, I've tried fixing it but I can't make or find a working solution, can someone help me?