본문 바로가기
알고리즘/Codewars

[Codewars] Break camelCase (6 kyu) / JavaScript

by fluss 2023. 2. 14.

https://www.codewars.com/kata/5208f99aee097e6552000148

 

Codewars - Achieve mastery through coding practice and developer mentorship

A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!

www.codewars.com

 

DESCRIPTION:

Complete the solution so that the function will break up camel casing, using a space between words.

 

Example

"camelCasing"  =>  "camel Casing"
"identifier"   =>  "identifier"
""             =>  ""
 

코드

// complete the function
function solution(string) {
  let result = "";
  for(let x of string){
    if(x === x.toUpperCase()) result += " ";
    result += x;
  }
  return result;
}

댓글