알고리즘 55 - Double Char

tamagoyakii·2021년 10월 18일
0

알고리즘

목록 보기
55/89

Q.

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

doubleChar("String") ==> "SSttrriinngg"

doubleChar("Hello World") ==> "HHeelllloo WWoorrlldd"

doubleChar("1234!_ ") ==> "11223344!!__ "

A)

function doubleChar(str) {
  let ret = '';
  for (el in str) ret += str[el] + str[el]
  return ret;
}

얼른 map 쓰는게 익숙해지는 날이 오길.......

0개의 댓글