Find the starting and ending indices of all repeated characters from a string
Find the starting and ending indices of all repeated characters from a string
Photo by Lino on Unsplash
const input =“hellooooloo”;
const op = getRepeated(input);
console.log(op) // [(2,3), (4,7), (9,10)]
function Indicies(str){
let res = [];
let start = 0;
let end = 1;
while(start<=end && end<str.length){
if(str[start]===str[end]){
let diff = end - start;
if(diff==1 && end === str.length-1){
res.push([start,end]);
}
end++;
}else{
let diff = end - start;
if(diff>1){
res.push([start,end-1]);
}
start = end;
end++;
}
}
return res;
}
console.log(Indicies(input)); 메타데이터
- post_id
- 58ec57b9ee7f
- slug
- find-the-starting-and-ending-indices-of-all-repeated-characters-from-a-string-58ec57b9ee7f
- url
- https://medium.com/@ramnayan699/find-the-starting-and-ending-indices-of-all-repeated-characters-from-a-string-58ec57b9ee7f
- canonical_url
- https://medium.com/@ramnayan699/find-the-starting-and-ending-indices-of-all-repeated-characters-from-a-string-58ec57b9ee7f
- author_url
- https://medium.com/@ramnayan699
- status
- ok
- fetched_at
- 2026-06-15 20:49:13