marian74

hard words

Jul 14th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function hardWords(data) {
  2.     let text = data[0];
  3.     let wordsList = data[1];
  4.     let newText = '';
  5.     while (true) {
  6.         let pattern = /[_]+/;
  7.         let result = text.match(pattern);
  8.        
  9.         if (result === null) {
  10.             break;
  11.         }
  12.    
  13.         for (const word of wordsList) {
  14.             if (word.length === result[0].length) {
  15.                 newText = text.replace(result, word);
  16.                 text = newText;
  17.             }
  18.         }
  19.    
  20.     }
  21.    
  22.    
  23.     console.log(newText)
  24. }
Add Comment
Please, Sign In to add comment