Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

JavaScript find repeated character

Input:
S = "geeksforgeeks"
Output: g
Explanation: g, e, k and s are the repeating
characters. Out of these, g occurs first.


const repeatedCharacter = (str) => {
  for (let i = 0; i < str.length - 1; i++) {
    for (let j = i + 1; j < str.length; j++) {
      if (str[i] === str[j]) {
        return str[i];
      }
    }
  }
  return -1
};
console.log(repeatedCharacter("geeksforgeeks"));

Source by practice.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #JavaScript #find #repeated #character
ADD COMMENT
Topic
Name
2+3 =