Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

74
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda