Advertisement
nikolayneykov

Untitled

Mar 22nd, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     let textWords = input[0]
  3.     let wordsToReplace = input[1]
  4.     let regex = /\b(_+)(?=[\b.,]*)/g
  5.  
  6.     let match = regex.exec(textWords);
  7.  
  8.     while (match) {
  9.         textWords = textWords.replace(match[0], wordsToReplace.find(w => w.length === match[0].length));
  10.         match = regex.exec(textWords);
  11.     }
  12.     console.log(textWords)
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement