Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

72
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!