Advertisement
krustev_84

Untitled

Oct 3rd, 2020
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. function merlahShake(input) {
  2.  
  3. let text = input.shift();
  4. let pattern = input.shift();
  5.  
  6. while (pattern.length > 0) {
  7. let firstMatch = text.indexOf(pattern);
  8. let lastMatch = text.lastIndexOf(pattern);
  9.  
  10. if ((firstMatch > -1 && lastMatch > -1) && firstMatch !== lastMatch) {
  11.  
  12. let firstRemove = text.substr(firstMatch, pattern.length);
  13. let lastRemove = text.substr(lastMatch, pattern.length);
  14.  
  15. text = text.replace(firstRemove, '');
  16. text = text.replace(lastRemove, '');
  17.  
  18. let removeFromPatt = pattern[Math.floor(pattern.length / 2)]
  19. pattern = pattern.replace(removeFromPatt, '')
  20.  
  21. console.log('Shaked it.');
  22. } else {
  23. console.log('No shake.');
  24. console.log(text);
  25. break;
  26. }
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement