Skip to content

Latest commit

 

History

History
27 lines (22 loc) · 554 Bytes

double_char.md

File metadata and controls

27 lines (22 loc) · 554 Bytes

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!

My Solution

def double_char(str)
  str.chars.map { |ch| ch*2 }.join
end

Better/Alternative solution from Codewars

def double_char(str)
  str.gsub /(.)/, '\1\1'
end