Advertisement
krustev_84

Untitled

Oct 3rd, 2020
728
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 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.  
  8. let firstMatch = text.indexOf(pattern);
  9. let lastMatch = text.lastIndexOf(pattern);
  10.  
  11. if ((firstMatch > -1 && lastMatch > -1) && firstMatch !== lastMatch) {
  12.  
  13. text = text.split('');
  14. text.splice(firstMatch, pattern.length);
  15. text = text.join('');
  16. lastMatch = text.lastIndexOf(pattern);
  17. text = text.split('')
  18. text.splice(lastMatch, pattern.length)
  19. let removeFromPatt = pattern[Math.floor(pattern.length / 2)]
  20. pattern = pattern.replace(removeFromPatt, '');
  21. text = text.join('')
  22.  
  23. console.log('Shaked it.');
  24. } else {
  25. break;
  26. }
  27. }
  28. console.log('No shake.');
  29. console.log(text);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement