Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## NOT RESOLVED
- // From string = ('Hi Fred', 'Fred', 'Barney') >> replace pattern >> 'Hi Barney'
- const str = ('Hi Fred', 'Fred', 'Barney', 'Lodash');
- const replace = (str) => {
- const newArr = [];
- let newStr = '';
- const strSplit = str.split(' ');
- for (const item of strSplit) {
- if (item.length === 2) {
- continue;
- } else {
- newArr.push(item);
- }
- }
- newStr = newArr.toString();
- console.log(`Hi ${newStr}`);
- };
- replace(str); // 'Hi Lodash'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement