Find repeated words in paragrah a string javascript

Code examples

0
0

how to find repeated characters in a string in javascript

const getRepeatedChars = (str) => {
  const strArr = [...str].sort();
  const repeatedChars = [];
  for (let i = 0; i < strArr.length - 1; i++) {
      if (strArr[i] === strArr[i + 1]) repeatedChars.push(strArr[i]);
  }
  return [...new Set(repeatedChars)];
};

getRepeatedChars("aabbkdndiccoekdczufnrz"); // ["a", "b", "c", "d", "k", "n", "z"]
0
0

find repeated words in paragrah a string javascript

const str = "big black bug bit a big black dog on his big black nose";
const findDuplicateWords = str => {
   const strArr = str.split(" ");
   const res = [];
   for(let i = 0; i < strArr.length; i++){
      if(strArr.indexOf(strArr[i]) !== strArr.lastIndexOf(strArr[i])){
         if(!res.includes(strArr[i])){
            res.push(strArr[i]);
         };
      };
   };
   return res.join(" ");
};
console.log(findDuplicateWords(str));

Similar pages

Similar pages with examples

In other languages

This page is in other languages

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................