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

[Codewars] Double Char (8 kyu) / JavaScript

by fluss 2023. 3. 1.

https://www.codewars.com/kata/56b1f01c247c01db92000076

 

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:

Given a string, you have to return a string in which each character (case-sensitive) is repeated once.

Examples (Input -> Output):

* "String"      -> "SSttrriinngg"
* "Hello World" -> "HHeelllloo  WWoorrlldd"
* "1234!_ "     -> "11223344!!__  "

Good Luck!

 

코드

function doubleChar(str) {
  return str.split('').map(el => el.repeat(2)).join('');
}

댓글