String Doubled
Geoffrey Challen // 2020.9.0
Write a function called doubleString
. Given a String
"test", you should return "tteesstt".
Given "HaHa!" you should return "HHaaHHaa!!". Given the String
"" you should return "".
Given the null
String
return null
.
There are several ways to approach this problem, and you may want to look into either the
toCharArray
String
methods or Kotlin string indexing.
For example, if var test = "Test"
, then test[0]
is "T" and test[2]
is "s".
Keep in mind that adding two characters together will be done mathematically.
So, given a character 'x', if you want String
concatenation you need to do x + "" + x
.