Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

120
Visualizações
How to find similar string elements

function countFig(str) {
  let arr = str.split('');
  let newArr = [];
  let a = arr[0];
  let sum = 0;
  for (let i = 0; i < arr.length; ++i) {
    if ((i = arr.indexOf(a, i)) === -1) break;
    newArr.push(i);
  }
  return newArr
}
console.log(countFig('dddmmmmccccaaamm'))

I have stucked with a simple task and don't understand how to make the decision about it. There is one condition - do not use regular expressions. The task is to write a function that counts similar elements of a string so if we have dddmmmmccccaaamm, the function returns d3m4c4a3m2. Firstly I thought about converting string to array and using filter method but it is the wrong way. Now I think to find the first element of the array and compare it with each element in the loop, but don't know what to do next.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda