Advertisement
Kamend1

Untitled

Feb 27th, 2025
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve (words, string) {
  2.     wordsArr = words.split(', ');
  3.  
  4.     for (let word of wordsArr) {
  5.         let wordLen = word.length;
  6.         let secret = '\\*'.repeat(wordLen);
  7.         let regex = new RegExp(`(?<=\\s|^)${secret}(?=\\s|$)`, 'g');
  8.         while (regex.test(string)) {
  9.             string = string.replace(regex, word);
  10.         }
  11.     }
  12.  
  13.     console.log(string);
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement