Advertisement
xoxama

Replace

Apr 29th, 2020
860
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ## NOT RESOLVED
  2.  
  3. // From string = ('Hi Fred', 'Fred', 'Barney') >> replace pattern >> 'Hi Barney'
  4.  
  5. const str = ('Hi Fred', 'Fred', 'Barney', 'Lodash');
  6.  
  7. const replace = (str) => {
  8.   const newArr = [];
  9.   let newStr = '';
  10.   const strSplit = str.split(' ');
  11.   for (const item of strSplit) {
  12.     if (item.length === 2) {
  13.       continue;
  14.     } else {
  15.       newArr.push(item);
  16.     }
  17.   }
  18.   newStr = newArr.toString();
  19.   console.log(`Hi ${newStr}`);
  20. };
  21.  
  22. replace(str); // 'Hi Lodash'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement