Advertisement
KoctrX

Untitled

Aug 8th, 2024
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function parseTranscription(str) {
  2.     const regex = /(AI|User):/g;
  3.     const parts = str.split(regex).filter(part => part.trim() !== '');
  4.    
  5.     // Преобразуем части в массив объектов
  6.     const messages = [];
  7.     for (let i = 0; i < parts.length; i += 2) {
  8.         messages.push({
  9.             sender: parts[i].trim(),
  10.             message: parts[i + 1].trim()
  11.         });
  12.     }
  13.  
  14.     return messages;
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement