[ASSIGNMENT] : Get the Middle Character

TASK : You are going to be given a word. Your task 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. For Example :: getMiddle("happy") --> return "p" getMiddle("codings") --> return "i" getMiddle("SoloLearn") --> return "L" getMiddle("playground") --> return "gr" NOTE : Spaces are ignored! #Output : The middle character(s) of the word represented as a String! HappyCodings!:-)

5/16/2018 8:31:09 AM

Danijel Ivanović

33 Answers

New Answer


My try 👇 https://code.sololearn.com/WyZ4EAaDQPu1/?ref=app






The task is updated for the reason that you are taking the white space as part of a word! If the word's length is odd, return the middle character. If the word's length is even, return the middle 2 characters. --> Spaces are ignored! Thank you all! 👍😉


Kotlin oneliner 😉 https://code.sololearn.com/cP2ADjwgKj7P/?ref=app https://code.sololearn.com/cia9VCaBIEbV/?ref=app https://code.sololearn.com/cc1G4NQn0QL7/?ref=app https://code.sololearn.com/cN7P94XLLew6/?ref=app




pretty much the same as others solutions https://code.sololearn.com/cPJnv6Cqmls3/?ref=app


My try;😉 https://code.sololearn.com/clBMpeI7NB3y/?ref=app


My try in JS: https://code.sololearn.com/Wd0mML1T8znr/?ref=app




My Python-Solution: https://code.sololearn.com/cxzGCL5p4ARH/?ref=app


Another pythoneliner https://code.sololearn.com/c42cvAa6AWbn/#py


Easy One https://code.sololearn.com/cJTkUivxt80f/?ref=app


Yeah, Luka will do it in one line 😁 Here is mine https://code.sololearn.com/c9hk0oOhzuC8/?ref=app


My implementation https://code.sololearn.com/cxJ28Jr14DI1/?ref=app


My code https://code.sololearn.com/cvWzuTi71fTU


My try here https://code.sololearn.com/c3MQqSu5Vc32/?ref=app Note - The challenge has been updated. Earlier it didn't talk of space within the word but now it does ! My code does not handle space as of now.


my python code https://code.sololearn.com/c9c7kgGb3ibW/?ref=app


Python oneliner: https://code.sololearn.com/cVi7jKs1e7JL/?ref=app


Updated try for updated challenge https://code.sololearn.com/cBbc5gGIe0Jx/?ref=app