Advertisement
Lulunga

Text Processing 01. Reveal Words

Jul 19th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function revealWords(words, textTemplates) {
  2.     words = words.split(', ');
  3.     let templates = textTemplates.split(' ');
  4.     for (let el of templates) {
  5.         if (el === '*'.repeat(el.length)) {
  6.             for (let i = 0; i < words.length; i++) {
  7.                 if (el.length === words[i].length) {
  8.                     templates.splice(templates.indexOf(el), 1, words[i]);
  9.                 }
  10.             }
  11.         }
  12.     }
  13.     console.log(templates.join(' '));
  14.  
  15.  
  16. }
  17.  
  18. /*Alternative solution
  19. function revealWords(words, textTemplates) {
  20.     words = words.split(', ');
  21.     words.forEach(element => {
  22.         textTemplates = textTemplates.replace('*'.repeat(element.length), element);
  23.     });
  24.     console.log(textTemplates);
  25. }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement