kstoyanov

08. Hard Word

Jul 17th, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(args) {
  2.   const text = args.shift().split(' ');
  3.   const words = args.pop();
  4.  
  5.   words.forEach((newWord) => {
  6.     const searchWord = '_'.repeat(newWord.length);
  7.  
  8.     text.forEach((word, index) => {
  9.       if (word === searchWord || word === (`${searchWord},`) || word === (`${searchWord}.`)) {
  10.         text.splice(index, 1, newWord);
  11.       }
  12.     });
  13.   });
  14.  
  15.   console.log(text.join(' '));
  16. }
Add Comment
Please, Sign In to add comment