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

104
Visualizações
Function to determine if it is possible to make the one string to be equal with the other

function to determine if it is possible to make the first input equal to the second input by either capitalizing or removing letters. Cannot interchange the positions of the letters.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

const canReplace = (str1, str2) => {
  const letters1 = str1.split('')
  const letters2 = str2.split('')
  let lastIdx = -1

  for (let l2 of letters2) {
    const idx = letters1.findIndex(l1 => l2 === l1 || l2.toLowerCase() === l1)
    if (idx > lastIdx) {
      lastIdx = idx
    } else {
      return false
    }
  }

  return lastIdx !== -1

}

console.log(canReplace('abCde', 'BCD'))
console.log(canReplace('Abcdef', 'ACE'))
console.log(canReplace('ABCD', 'CBD'))
console.log(canReplace('ABC', 'AbC'))

about 4 years ago · Juan Pablo Isaza Relatório

0

Idea is to take one letter at a time from right string, and try to “cross out” some letters from left string by certain rules. For each letter from right string, it must be able to cross out at least one letter from left string, otherwise the check fails.

function check(left, right) {
  const chars = right.split('');
  for (const c of chars) {
    let i = left.indexOf(c);
    if (i == -1) i = left.indexOf(c.toLowerCase());
    if (i == -1) return false;
    left = left.slice(i + 1);
  }
  return true;
}
about 4 years ago · Juan Pablo Isaza Relatório
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