7 kyu

Get the Middle Character

15,429 of 281,518Shivo
Description
Loading description...
Fundamentals
Strings
  • Please sign in or sign up to leave a comment.
  • lennyerik Avatar

    There is no mention in the challenge description on whether all the strings passed to the program contain exclusively ASCII characters or whether other unicode symbols are possible. I worked under the assumption that the function only has to work with ASCII and the tests ended up passing, but adding this to the challenge description would be nice for low-level languages like C, C++, Rust, ...

  • cheekygerold Avatar

    is the function is passed a non-empty string per the description, then why does the random tests pass an array?

  • hobovsky Avatar

    Description needs some cleanup: the note about error in JS tests shold be removed, and JS tests should be fixed. Examples can be made language-neutral.

  • jdizzydizzle Avatar

    Found this really good. Quite challening but not too challenging so I'd give up. Kept me going to find the answer. Nice one

  • hellobroman Avatar

    This comment has been hidden.

  • metatable Avatar
  • user9404554 Avatar

    Impossibly difficult IQ challenge == 20000000000000000000000000000

  • Alfa94_br Avatar

    I had to get help from chatGPT to solve it. It was a little bit difficult :( Could someone explain to me how can we solve any problem at coding alone in the most time? How can we get our own creative solution and develop one of the most difficult spirit of a coder? Cretivity to solve anything?

  • jingchun Avatar

    This comment has been hidden.

  • hawariMuflihMunte Avatar

    This comment has been hidden.

  • neonel Avatar

    This comment has been hidden.

  • usseryr Avatar

    This comment has been hidden.

  • russintech Avatar

    This comment has been hidden.

  • Signalls2 Avatar

    This comment has been hidden.

  • MogadishuDev Avatar

    This comment has been hidden.

  • RandomGuy45 Avatar

    Change "Your job is to return the middle character of the word" to "Your job is to return the middle character(s) of the word" :)

  • Bizdoc Avatar
      assert_eq!(get_middle("ƒoo"), "o");
    

    I suggest to add this casetest too because the string "ƒoo" contains a non-ASCII character, which may behave differently than ASCII characters in certain operations.

    for example the len of ƒoo is 4 not 3.

      assert_eq!("ƒoo".len(), 4); // fancy f!
    
  • astralisdev Avatar

    This comment has been hidden.

  • mkanj Avatar

    i can't find the solution, can someone help me plz?!

  • Rideuz Avatar

    Exactly

  • John Calimoso  Avatar

    heyy, the kata is working on yah browser guys?? mine keep on returning an error "This error was caused due to an issue processing the web request, not because of an issue executing your code"

  • XCaliba090728 Avatar

    Hi all

    Can someone kindly take a look at my code for the "Get Middle Characters" challenge? I can't for the life of me, figure out why it isn't working. Are there bugs in some of the Katas?

  • akar-0 Avatar
  • sj95126 Avatar

    you do not need to worry about your solution timing out

    I took that as a challenge.

  • KrustyKarpet Avatar

    Description is a little inaccurate. It states the input is 0 < str < 1000 but this is wrong as you are given 0 length strings in some of the tests at least for Go.

    change the input description to 0 =< str < 1000

  • rxe Avatar
  • CODER_COFFEE Avatar

    This comment has been hidden.

  • maffin immortal Avatar

    This comment has been hidden.

  • vladbark Avatar

    Trying to compile in TypeScript. Something wrong with tests.

    test.ts:6:23 - error TS7006: Parameter 'expected' implicitly has an 'any' type. 6 function test(string, expected) {

    If try to add types to test function explicitly:

    test.ts:7:31 - error TS2339: Property 'Challenge' does not exist on type 'typeof import("/workspace/default/solution")'. 7 assert.strictEqual(solution.Challenge.getMiddle(string), expected) ~~~~~~~~~ test.ts:1:22 - error TS6053: File '/runner/typings/main/ambient/mocha/index.d.ts' not found. 1 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ test.ts:2:22 - error TS6053: File '/runner/typings/main/ambient/chai/index.d.ts' not found. 2 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  • prjavelin Avatar

    This comment has been hidden.

  • trashy_incel Avatar

    This comment has been hidden.

  • Klondike Avatar

    There is something worng with the Kotlin test.

    My solution workd fine in repl, but test shows errors here

  • CloudHunter Avatar

    On Google Colab my code works correct (also with strings from the test), but here i've catch error message (for 'test' => None not 'es')...

    Were is I wrong?

    Code: *** Hide. ready to show

  • PatrickT80 Avatar

    This comment has been hidden.

  • Polper Avatar

    This comment has been hidden.

  • metatronic Avatar

    in Kotlin the function name is Kata which is incorrect as the tests dont compile because of name mismatch

  • profatilov Avatar

    This comment has been hidden.

  • ejini战神 Avatar

    Typescript: missing return type in solution setup ~~

    Typescript 3.3 or above should be enabled

  • emopinback Avatar

    This comment has been hidden.

  • Totuarez Avatar

    Issue for Kotlin: The given function stub is called "Kata", but "getMiddle" is expected for the tests.

  • a.merezhanyi Avatar

    Please review fixed Go translation. Approve please.

  • mahbubaalahiakib2 Avatar

    Ah, could not solve it

  • Arctic_DLS Avatar

    This comment has been hidden.

  • honis7 Avatar

    This comment has been hidden.

  • TuCrG123 Avatar

    I don't know where to start with this kata, can someone help? java btw

  • user9644768 Avatar

    Ruby 3.0 should be enabled.

  • lianfangti Avatar

    This comment has been hidden.

  • MAN_EATER Avatar

    This comment has been hidden.

  • petejoo Avatar

    This comment has been hidden.

  • pjw Avatar

    The Kotlin-variant had misleading function name: fun Kata(). Most of the time I spent on this assignment was to figure out if the function name was correct or not. Apparently, it should be fun getMiddle()

  • moemia12 Avatar

    This comment has been hidden.

  • Alexia.g Avatar

    This comment has been hidden.

  • ePath Avatar

    interpolation $"" does not work here, so I do it without it and it still doesn't work. I used the test cases and my code works just fine in VS but when I run it here I get errors

  • pajeet Avatar

    This comment has been hidden.

  • Chris-ton Avatar

    This comment has been hidden.

  • Jackie1430 Avatar

    This comment has been hidden.

  • munir.prog Avatar

    This comment has been hidden.

  • tenzin_123 Avatar

    This comment has been hidden.

  • Alejandro8khan Avatar

    This comment has been hidden.

  • Gita-mw Avatar

    This comment has been hidden.

  • najma-amin Avatar

    any help on returnig the middle character

  • noberhess Avatar

    I am a beginner using Java and I do not know where the input comes from. I thought it would be input as a string and assigned to the parameter word, but when i used word.length, it said it did not recognize the word variable. What is the problem?

  • nekimoto Avatar

    This comment has been hidden.

  • LofuFoxy Avatar

    This comment has been hidden.

  • JavaCommons Avatar

    Dart translation submitted. Follow the link and APPROVE please :)

  • jacobrford Avatar

    This comment has been hidden.

  • droodic Avatar

    maybe should be 8kyu

  • KrunalLathiya Avatar

    This comment has been hidden.

  • jrd656 Avatar

    This comment has been hidden.

  • CorneliaRapp2 Avatar

    This comment has been hidden.

  • iosa Avatar

    This comment has been hidden.

  • rabbit_binary7 Avatar

    In the random generator (reference Javascrip solution), this line is wrong: var x = randint(0, alph.length);. randint(a, b) random integer from a to b inclusive. It is possible that x might have alph.length ( == 52) ----> alph[52] === undefined. So we should delete 1 from Math.floor(Math.random() * (b - a + 1) + a) (randint function)!

  • NazarBEST Avatar

    Hello, I think that this test have mistake. When I checked my code I don't passed 1 test which had 529 symbols and test said that i have to return 2 symbols. As I understand, when all simbols of string is even number we have return 2 symbols, else 1 symbol. If I not right, please explain me why?

  • stellartux Avatar
  • massigarg Avatar

    This comment has been hidden.

  • number_118 Avatar

    This comment has been hidden.

  • axjasf Avatar

    This comment has been hidden.

  • BLTinA2 Avatar

    i solved the kata and it passed all tests. i just don't see how to submit it. I just started Codewars yesterday.

  • hiccups Avatar

    This comment has been hidden.

  • Karg Avatar

    hello, sorry, i need help i have \ instead of <, when i tape in < why ?

  • gvavamis Avatar

    My code works fine in PyCharm. but in kata platform some sumples says wrong answare. in pycharm the same sumple returns the correct answare

  • Embersongs Avatar

    This comment has been hidden.

  • alexlepri Avatar

    This comment has been hidden.

  • oads Avatar

    There is a problem with the question, If you do the question in Java and for the odd questions testing only return word.substring(0);

    It should return the full test word back as a check, it only returns [esting] Which is incorrect with how the substring works and the indexing of the letters.

    This needs to be fixed.

  • michaelshoup Avatar

    This comment has been hidden.

  • Bard Programer Avatar

    This comment has been hidden.

  • Bard Programer Avatar

    nvm, i just reload the page and it worked

  • Bard Programer Avatar

    My code works on visual studio but not here, why?

  • AcidA Avatar

    This comment has been hidden.

  • CameronT0101 Avatar

    This comment has been hidden.

  • C0d3r4ppr3nt1c3 Avatar

    pretty ez should be on 8 kyu

  • xavierguihot Avatar

    Scala translation ready for review.

  • Integerous Avatar

    This comment has been hidden.

  • arnavb12 Avatar

    This comment has been hidden.

  • ivoszz Avatar

    Translated to Go.

  • krzysztofor Avatar

    Bug in tests or description

    in Details: length 0 < str < 1000 but Erlang tests contain empty string so function should handle special case

  • Bubbler Avatar

    NASM translation submitted.

  • Voile Avatar

    Ruby (and probably Crystal and other languages too): strings are mutable and random test is vulnerable to input modification.

  • martin6724 Avatar

    I'm not quite sure why the random tests in ruby are expected to display values outside the middle of the string. Maybe I'm missing something. Can someone explain why expected values exclude the middle characters for random tests and not for primary tests?

    Testing for bLXT It should work for random inputs too - Expected: "bT", instead got: "LX" Testing for hBRnHu It should work for random inputs too - Expected: "BH", instead got: "Rn" Testing for FSCfE It should work for random inputs too - Expected: "Sf", instead got: "C"

  • tlaiful Avatar

    This was fun!

  • Chrono79 Avatar

    This comment has been hidden.

  • ygspassov Avatar

    There are problems with the tests. My script runs on my PC without issues but all tests fail here.

  • @conydericky Avatar

    i am looking for a girlfriend

  • @conydericky Avatar

    its so cool

  • @conydericky Avatar

    i like this kata

  • FrozenPigs Avatar

    I thought my one line was good until I saw that top one heh.

  • AniGonner Avatar

    This comment has been hidden.

  • AniGonner Avatar

    This comment has been hidden.

  • RoQu Avatar

    This comment has been hidden.

  • mneely1 Avatar

    This comment has been hidden.

  • maipatana Avatar

    BF Translation kumited

    Please review and let me know if there's any suggestion. My first translation ever.

  • BaronWan Avatar

    Time: 0ms Server Execution Error:

    The server timed out waiting for the request to be processed. This may be due to high server load. Please try your request again.

    Request Error: Request failed with status code 500

    This error was caused due to an issue processing the web request, not because of an issue executing your code. You can retry the request.

  • DanielKimani Avatar

    This comment has been hidden.

  • Asad1212 Avatar

    too much hard vork

  • Asad1212 Avatar

    wat is dis

  • millian8894 Avatar

    Hi, Please help, I am new here and using C++,the processes are quite confusing. Do i solve the challenge with my own method or do i go with the way it was writing in the solution window? Also, I solved the problem and it currently bruns on my laptop but when i click on the run sample test button, it gives this error:

    Log:

    es

    Expected: equal to es

    Actual: test

  • Xavi3r Avatar

    Hi, when testing my function I get the following error. I see no difference between the results. Time: 98ms Passed: 0 Failed: 1 Errors: 1 Test Results: Log es None should equal 'es' does the test properly work?

  • Mobimzy Avatar

    Hi, am new here trying to figure out my first test( showing d middle char) Thanks.

  • mariekerkstoel Avatar

    This comment has been hidden.

  • emr0327 Avatar

    how to use 'import' for Python

    i.e. I want to use the floor() and ceil() methods in my code. The math 'library' is needed to do so

    codewar does not seem to support: import math

    Any feedback/help?

  • mentalplex Avatar

    R Translation kumited

    Please review and make any suggestions for changes or approve :)

    I commented the test suite to describe the reference solution, in case you're unfamiliar with R

  • iyiolaosuagwu Avatar

    This comment has been hidden.

  • alhamz Avatar

    This comment has been hidden.

  • user8766935 Avatar

    This comment has been hidden.

  • welbinator Avatar

    So um...it says I'm going to be given a word...so....where's the word?

  • andybeak Avatar

    The site throws an error about the mb_strlen function not existing (http://php.net/manual/en/function.mb-strlen.php).

    If you just use strlen then if the string includes any multibyte characters your program won't work.

    It's really limited to assume that people visiting your website only come from America and only use latin characters.

  • krishnapvsb Avatar

    This comment has been hidden.

  • Jerrod Avatar

    This comment has been hidden.

  • jzd Avatar

    I just unknow how to use the website.Eh,why is the recommanded test so different from what I had learnt.

  • JanMaria Avatar

    This comment has been hidden.

  • zkwentz Avatar

    The instructions specify 0 < str < 1000, so I add this to my test cases.

    However, the tests that the Kata has, go over 1000, and have no specification for how the getMiddle(s) function should resolve this.

  • veveux Avatar

    I'm pressing ATTEMPT button, all tests pass, but I don't get the rank points. Does anybody know why?

  • Lik Avatar

    This comment has been hidden.

  • kmedema Avatar

    This comment has been hidden.

  • jo-quin Avatar

    This comment has been hidden.

  • Orhun Vatansever Avatar

    This comment has been hidden.

  • terabyte666 Avatar

    This comment has been hidden.

  • gulkodmitriy Avatar

    Is it normal that instructions says that maximum length is 1000, but in tests we have 8 tests with length bigger then 1000&

  • SirLucidus Avatar

    This comment has been hidden.

  • GoPotato Avatar

    This comment has been hidden.

  • FlorianGrundig Avatar

    Hi, thx for the kata - I've trouble to submit my solution: the test-suite is passing but I've some output on stderr (which prevents me from submitting?):

    /tmp/haskell116115-18-iam4dq.uei7vcayvi/Codewars/G964/Getmiddle/Test.hs:11:1: Warning: Tab character

    /tmp/haskell116115-18-iam4dq.uei7vcayvi/Codewars/G964/Getmiddle/Test.hs:12:1: Warning: Tab character

    /tmp/haskell116115-18-iam4dq.uei7vcayvi/Codewars/G964/Getmiddle/Test.hs:13:1: Warning: Tab character

    /tmp/haskell116115-18-iam4dq.uei7vcayvi/Codewars/G964/Getmiddle/Test.hs:23:1: Warning: Tab character

    /tmp/haskell116115-18-iam4dq.uei7vcayvi/Codewars/G964/Getmiddle/Test.hs:24:1: Warning: Tab character

    /tmp/haskell116115-18-iam4dq.uei7vcayvi/Codewars/G964/Getmiddle/Test.hs:25:1: Warning: Tab character

    /tmp/haskell116115-18-iam4dq.uei7vcayvi/Codewars/G964/Getmiddle/Test.hs:26:1: Warning: Tab character

    /tmp/haskell116115-18-iam4dq.uei7vcayvi/Codewars/G964/Getmiddle/Test.hs:27:1: Warning: Tab character

  • ezequielo123 Avatar

    This comment has been hidden.

  • drpicox Avatar

    Typescript version test contains the solution.

  • kanat028 Avatar

    randTests(MiddleTests) Log tS this is my result why wrong??? ✘ Middle of VpqjQxytKEcUDHJFMVDNJtRLNjtAAsFzrSevwWYVMgSJWuNghMNyXIAquRUSHFwWhzvCEkoYYdCRyjUQFPKEhlkyRWjOkhBAsvgEONxbFLMxhkxvEtJXZMxgdBJozEdjbezJsLMBUNQxliNUpHsyqNsSgfLnBKbpcpOAJEfegPiBxFKwtwdrgkArLnyQwLkVVcritSFSHGFQBVHdsKNkTVOQKOgrazDAyakLwLHuySjEdyBSBhpOLsJnwfuoxnEEsLazntgBEyHTFFLvduzYVplTpbAeLZsTLBFmsDVfjfQaCQuVokEEgtPkDuKeviitjNNvlkNAYsjsCAZLhIwgjaazIXXgizDIjOaXVmcBOGwPfKcBBCqFcBzLVSZoGOaeohsWcEbBWs is tS not expected:<[tS]> but was:<[]>

  • kanat028 Avatar

    This comment has been hidden.

  • Nalcarya Avatar

    Cannot submit this kata in ruby. It has passed all tests, but when I click "submit" btn it just goes through the tests again. Thank you in advance.

  • pappacarr Avatar

    This comment has been hidden.

  • jtobyh_ Avatar

    I solved this recursively, mainly because I'm a beginner and wanted to practise doing so. Any thoughts on best practice in terms of effinciency/memory/ other considerations?

  • johnde02 Avatar

    This comment has been hidden.

  • raghuvir Avatar

    This comment has been hidden.

  • Rdedmon13 Avatar

    This comment has been hidden.

  • cian mcg is the man Avatar

    This comment has been hidden.

  • KirKaz12 Avatar

    This comment has been hidden.

  • Thugnificent Avatar

    Very nice, my first app i did with Python and on this website and overall feel very satisfied :D

    Thanks!

  • dnolan Avatar

    Great Kata! C++ Kumited :)

  • psyapo Avatar

    Smtg wrong with Ruby Random test...

    Random tests Testing for diFpFlyWfzXcEHNCIlz It should work for random inputs too - Expected: "fX", instead got: "z" Testing for sPSUvuIIrCZlcrYHino It should work for random inputs too - Expected: "rZ", instead got: "C" Testing for yCTuZX It should work for random inputs too - Expected: "CZ", instead got: "Tu"

  • PG1 Avatar

    Shivo, I really liked this kata - great job

  • g964 Avatar

    I think you have not been notified: Clojure translation kumited-)

  • biskinis Avatar

    Hi. Nice Kata. But why specify an upper bound on the length of the input string?

  • g964 Avatar

    Nice! Coffeescript translation kumited.

  • GiacomoSorbi Avatar

    Ranked, upvoted, translated :)

    Please note for future katas that the function names should always start with a lowercase character in JS, as the capitalized version is usually reserved for classes.