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

73
Visualizações
Inserting string value using substring not returning intended output

this simple program I am making solution isn't returning the intended output.

if the string includes the phrase camelCasing the expect output should be camel Casing also, if the string includes any other words like camelCasingCarrier the output should be camel Casing Carrier

if the string includes any other phrase, it should just return the string.

function solution(string) {
  let newString = null;
  let stringToAdd = ' '
  if (string.includes('camelCasing')) {
    for (let i = 0; i < string.length; i++) {
      let letter = string[i];
      if (letter == letter.toUpperCase()) {
        newString = string.substring(0, letter) + stringToAdd + string.substring(letter);
      }
    }
    return newString;
  } else {
    return string;
  }
}

My current output is camelCasingCarrier with a space at the beginning rather than the expected output. What is my issue and how should I fix this? Thanks again :)

UPDATE

Corrected the prior codes errors here:

function solution(string) {
  let newString = '';
  let stringToAdd = ' '
  if (string.includes('camelCasing')) {
    for (let i = 0; i < string.length; i++) {
      let letter = string[i];
      if (letter == letter.toUpperCase()) {
        newString += ' ' + letter;
      } else {
        newString += letter;
      }
    }
    return newString;
  } else {
    return string;
  }
}
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