2018-12-25 16:13:44 UNSELECTED

Unknown type code

Copy Copied! Full
#<detalis> #You are going to be given a word. #Your job is to return the middle character of the word. #If the word's length is odd, return the middle character. #If the word's length is even, return the middle 2 characters. #examples Kata.getMiddle("test") should return "es" Kata.getMiddle("testing") should return "t" Kata.getMiddle("middle") should return "dd" Kata.getMiddle("A") should return "A" #my answer def get_middle(s) return s if s.length < 3 if s.length.even? s.chars.select.with_index{ |st,i| i == s.length / 2 || i == s.length / 2 - 1 }.join else s.chars.select.with_index{ |st,i| i == s.length / 2}.join end end #bestpractice def get_middle(s) s[(s.size-1)/2..s.size/2] end