Return the Middle Character(s) of a String

Published by Matt in

Create a function that takes a string and returns the middle character(s). If the word's length is odd, return the middle character. If the word's length is even, return the middle two characters.

Examples

getMiddle("test") ➞ "es"

getMiddle("testing") ➞ "t"

getMiddle("middle") ➞ "dd"

getMiddle("A") ➞ "A"

Notes

All test cases contain a single word (as a string).

Watch a quick demo on how Edabit works.