Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const str = 'Това е просто тест. Това е проверка на уменията. Ако се справите, ще бъдете поканени за участие.';
  2.  
  3. let searchedSymbolIndex = str.indexOf('.');
  4.  
  5. const words = [];
  6.  
  7. // alert(searchedSymbolIndex);
  8.  
  9. while (searchedSymbolIndex !== -1) {
  10.  
  11.   const intervalIndex = str.lastIndexOf(' ', searchedSymbolIndex);
  12.  
  13.   const lastWord = str.substring(intervalIndex, searchedSymbolIndex);
  14.  
  15.   words.push(lastWord);
  16.  
  17.   searchedSymbolIndex = str.indexOf('.', searchedSymbolIndex + 1);
  18. }
  19.  
  20. alert(words);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement