Advertisement
MiroJoseph

Split Strings

Apr 16th, 2020
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.33 KB | None | 0 0
  1. My:
  2. object Kata {
  3. def solution(str:String):List[String]=
  4.   {
  5.     if(str.nonEmpty)
  6.         str.split("(?<=\\G..)").toList.map(x=>{
  7.     if(x.length ==1)
  8.          x+"_"
  9.     else x
  10.   })
  11.     else
  12.       List()
  13.   }
  14. }
  15.  
  16. Other:
  17. object Kata {
  18.  
  19.   def solution(s: String): List[String] = {
  20.     s.grouped(2).map(_.padTo(2, '_')).toList
  21.   }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement