Answers for "find repeated words in paragrah a string javascript"

0

how to find repeated characters in a string in javascript

/* Time complexity of solution: O(n) */
const getRepeatedChars = (str) => {
 	const chars = {};
    for (const char of str) {
        chars[char] = (chars[char] || 0) + 1;
    }
    return Object.entries(chars).filter(char => char[1] > 1).map(char => char[0]);
}

getRepeatedChars("aabbkdndiccoekdczufnrz"); // ["a", "b", "c", "d", "k", "n", "z"]
Posted by: Guest on April-16-2021
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));
Posted by: Guest on April-18-2021

Code answers related to "find repeated words in paragrah a string javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language