Todorov_Stanimir

03. Anonymous Vox Program.Fundam.Exam - 05 Nov 2017

Jul 14th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. anonimousVox = ([textinput, placeholdersinput]) => {
  2.     let pattern = /([A-Za-z]+)(?<name>.+)(\1)/g
  3.     placeholders = placeholdersinput.match(/(?<={)([\w\s]+)(?=})/gi);
  4.     let text = textinput;
  5.     let index = 0;
  6.  
  7.     while ((word = pattern.exec(textinput)) !== null) {
  8.         text = text.replace(word.groups['name'], placeholders[index]);
  9.         index++
  10.     }
  11.     console.log(text);
  12. }
  13. anonimousVox(['Hello_mister,_Hello', '{ Jack }', '']);
  14. anonimousVox(['ASD___asdfffasd', '{this}{exam}{problem}{is}{boring}', '']);
  15. anonimousVox(['Whatsup_ddd_sup', '{Dude}']);
  16. anonimousVox(['HeypalHey______how_ya_how_doin_how', '{first}{second}']);
Advertisement
Add Comment
Please, Sign In to add comment