6 kyu
WeIrD StRiNg CaSe
24,278 of 49,787xDranik
Loading description...
Strings
Algorithms
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Tests for C# are incredibly inconsistent, sometimes accounting for the empty spaces as an indexable value and sometimes not
You seem to get the instructions wrong. Each word should be weird-cased separtely, and not the whole sentence. Positions of spaces are not relevant when weird-caasing a word.
ah understood. thank you
Poorly explained kata. The index of the first character of EACH word is 0.
the test don't work in python
to_weird_case should return the correct value for a single word 'ThIs ' should equal 'ThIs' 'Is ' should equal 'Is' Completed in 0.09ms should return the correct value for multiple words 'ThIs Is A TeSt ' should equal 'ThIs Is A TeSt' Completed in 0.03ms Completed in 0.20ms
And what is wrong with these tests? The messages you show say that your answers have unnecessary trailing spaces. Should the trailing spaces be accepted? Or is the issue something else?
It was my fault, I didn't notice the trailing spaces or that the tests considered them. I finally added a strip to the output to fix it.
This comment has been hidden.
In which language does that happen?
This comment has been hidden.
No random tests in
CS
Ruby
Missing sample and fixed tests for empty string in almost all languages except C, C++, JS
PHP
No fixed tests
Random tests are not random :(
New here and newish to c++. was wondering if someone could clarify one point that isn't necessarilly specific to this kata but came to mind when trying to find a solution. the snippet of code given at the beginning of this kata included a return statement of the string_view (ie. return {str.begin(), str.end()}; ). None of the other solutions I saw kept this part of the code. Instead a lot of the solutions created a new string and returned the value of that string instead. Was I wrong in thinking that the solution needed to include this bit? Because I got stuck in trying to figure out how to modify the string_view if that was being returned. I finally just gave up and also changed the return statement to use a new string variable instead. Any help would be appreciated.
You are free to do or return whatever you want inside (and sometimes even outside) of the function, as long as the function signature stays the same
Do your magic, wizard :^)
Great kata. Thanks
Good kata, but it is a 7 kyu level.
Before clicking that the problem has been solved, you need to check the code. Everything is written very clearly here that the code with the wrong test is expected. P.S for MikChan(expected is an expectation from your test and it is not correct. since the first character must be uppercase)
It's impossible to figure out what your code is, use markdown to paste your code
Ah, okay, I figured out what is going on.
The expectation is correct. Please, check how the
doTest
function works, you have its definition on your hands.So, kata is okay, your code is at fault.
Hint: There's probably a few reasons folks say not to use global scoped variables in your code. You just managed to hit one of these reasons.
Hint 2: this
OP: posts unformatted code
Also OP: " Everything is written very clearly"
See this paragraph for info how to post your code very clearly.
This comment has been hidden.
Because your code gives a wrong answer. For the input "ZTK AUWyK Dy HqV" it should return "ZtK AuWyK Dy HqV", but returns "zTk AuWyK Dy HqV" (the first letter must be uppercase).
Not an issue.
Are you laughing? My code will return the correct value 'ZtK AuWyK Dy HqV' (it also says that he was just expecting the meaning of the first character with a small letter)
Your function has a bug, it returns wrong results when it's called more than once. Try following test cases:
Run both tests one after another, and you will the that the first one passes, and the second one fails.
Lua translation!
Approved.
C++ Translation
Please, review and approve/reject.
Approved.
Check this: https://www.codewars.com/kata/52b757663a95b11b3d00062d/discuss#67542f9cd8369da1c011f1e7
I am no expert, but this was easy enough to be classified as 7kyu, though I did notice some patterns in here that matched other six kyu problems that I couldn't solve
omfg bonk.io wdb reference!!!!!!!
In description said, that spaces will be presented only in case, where will be several words, but in test data there was string only with 4 spaces " ". So test didn't match the description.
In what language?
in C#. Fixed.
'ThIs iS A TeSt' to equal 'ThIs Is A TeSt' In this test, an output with capital letters in odd indices is expected, which does not agree with the instructions.
Read the description again, you're wrong. Also the posts below asking the same.
Because the instructions do not say what you think they say:
...indexed characters _in each word_
meaning, index each word individually, not throughout the indexing of the entire input.
Ohh I see. Thank you!
incomplete description, the example shows even index letters in small. Not clear whether to count the "spaces" or not."Weird string case" => "WeIrD StRiNg CaSe", here the letter C is at 13th index but still is in upper case.
Not a kata issue, read that again. Spaces are not part of words.
great little string manipulation kata. really tightly constructed, pleasure to work out
Issue with test cases: The kata says that even-indexed chars should be capitalized and odd-indexed chars, lowercased, but does not accept "ThIs iS A TeSt", even though the string satisfies both rules. The Kata therefore keeps on failing though the solution is right.
The index is relative to the start of each word, not the string as a whole. The phrasing in the description is a little awkward:
but it is there.
I keep having this error, and I dont know why, it doensnt make sense... Its C#, this is the test I can't to get to work.
Test Failed Whitespace should work too! Expected string length 4 but was 0. Strings differ at index 0. Expected: " " But was: <string.Empty> -----------^
The
issue
tag is for tracking problems with a kata that need to be addressed. You're asking about your own code, please don't use useissue
for that. Usequestion
or no tag at all.For debugging your solution, https://docs.codewars.com/training/troubleshooting might be useful.
But man, could you take a look at this Kata, I trully beleive there must be a error related to the test: "ShouldWorkForWhitespace", because its expecting to return a empty string of size 4, it doesnt make sense.
This comment has been hidden.
Mark your post as having spoiler content next time please. Your code only turns some letters to uppercase but doesn't do the opposite. Not a kata issue.
Misleading acceptance criteria (C#).
This comment has been hidden.
Hi. Please use the spoiler flag when you post some code in discussion so it is not available to users who didn't solve the kata (I have just put the flag on for you). Also, please use markdown tags to format your code or it is very discomfortable to read and hard to interpret, since the indentation is broken, see there how to do it: https://docs.codewars.com/references/markdown/#code-block
You can answer to this thread by adding your formatted code.
One thing I can tell you is that the instruction
s = s + "
is useless (it adds an empty string to a string, so it eventually produces the same string).thanks!I wirte it firstly.
Really bad description imo. Not sure why no one fixed it in so long.
Scala translation
Is this 6 kyu ?
should be seven kyu
There are always issues in codewars challenge! Kindly fix. When I work on it locally, the tests that failed in codewars worked correctly in vscode
It is pretty hard to know what to fix if you don't even tell us what the inputs were that failed.
Thank you for the reply. i have issues with these i put expected 'this' to equal 'ThIs' expected 'this Is A Test' to equal 'ThIs Is A TeSt'
Your code is wrong, the tests are fine. Your code only capitalized all words except the first one, and that's not what it should do. There is nothing to fix except your code here.
That is always false.
The description needs a little more formatting to explain the acceptance criteria. It's hard to understand the requirements for this solution and it took much longer to determine what exactly was being asked. I think listing out the requirements and the notes about the indexing would help a lot better.
don't forget to remove the last space. Some solution will help
I solved with the understanding that the same mutated object needed to be returned when the description stated return the "same string" but I noticed other people returned a string that was the same (in terms of the letter/space combination), but a different object altogether.
This ambiguity leaves the possibility for two different possible solutions. One which outputs two strings that are equal when compared as case-insensitive versions OR the same string object, but mutated with indicated capitalizations, so might be worth clarifying!
This comment has been hidden.
not a suggestion.
Java translation
Don't waste time on this kata. The index on string in examples vs test cases is not consistent
It is consistent. You're misunderstanding the instructions. How would it had been solved 383414 times otherwise? Did you read the post below yours?
I just solved it, so thank you. The author should have made the description more clear.
The tests are not consistent, in one they count spaces as an index of consideration, in another they don't count spaces
In what language?
They never count spaces, read the description again or similar posts below.
Please, add to the description more detailes that spaces " " are not converted toWeirdCase and should be not included to indexation.
'ThIs Is A tEsT' should equal 'ThIs Is A TeSt' its just inconsistant the first space on the left it goes from lowercase s to uppercase I but then on the last spazce its uppercase A and uppercase T
Read the posts below, it's been explained more than once, you have to start over in each word.
Everything is working correctly, but the tests are not running
Test Results:
toWeirdCase
should return the correct value for a single word expected 'ThIs ' to equal 'ThIs'
Completed in 2ms
should return the correct value for multiple words expected 'ThIs Is A TeSt ' to equal 'ThIs Is A TeSt'
Completed in 2ms
Hi @Smith3G - as you can see when you paste your results:
expected 'ThIs ' to equal 'ThIs'
expected 'ThIs Is A TeSt ' to equal 'ThIs Is A TeSt'
there is a space in your answers (at the end).
Tip: If you find it difficult to see such characters - in "string" based katas it is very common - just paste your error messages into your favourite text editor on your PC, or use code blocks
like this
where you can see the characters better.The problem should explicity state that each word is indexed seperately. Based on the explanation, "This is a test" should end up looking like "ThIs iS A TeSt" but the tests look for "ThIs Is A TeSt"
More like 7 kyu yeah
should not be 6
Tests cases are good but description is not good , i want to say you if there's another word the counting will start from zero. For example:
ThIs Is A TeSt --> every word counting starts at zero not as you think.
Thanks a lot!
Provided tests are inadequate. Some poorly written solutions slip thru. A test with all capital letters is strongly needed.
(OP's language was JavaScript) Fixed.
C translation (author gone)
Approved
Factor translation
Approved
Tests don't seem to be checking if the method is returning the same object as passed to it. I was able to pass tests by returning a new String.
The tests can be appended to check object_id
This is a good kata but the description is so poorly written. It took me 3 trials and reading through the discussions to finally understand what the kata is trying to achieve. I should not have to read the discussions to understand a kata.
And what is your suggestion? Propose a better description or explain what is missing there.
no answer from OP.
simple kata.
Took me a while to understand that each word starts new count! Nice Kata!
That cleared everything up for me. Holy cow this one sentence should be in the instructions for sure! Thank you!!
The kata says that even-indexed chars should be capitalized and odd-indexed chars, lowercased, but does not accept "ThIs iS A TeSt", even though the string satisfies both rules. Some users have observed that the "index" does not count spaces, but the term is never used this way in computer science, and no one would assume not to count spaces. If it is really the case that whitespace is not to be observed in the calculation of the "index", this should be specified in the kata.
This comment has been hidden.
My mistake, thanks for the clarification.
No problem, added "and you need to start over for each word" to the kata description to make it clearer.
Great, I think that really makes the use of "index" in this context clear. Good kata overall.
Nice kata!
According to the condition it should be equal to "ThIs iS A TeSt", since every even character is uppercase remeber Even numbers UPPER Odd numbers lower Spaces Doesn't Count.
Encountered the same issue..
Every new word is reset to start with uppercase again.
'ThIs iS A TeSt' should equal 'ThIs Is A TeSt' It means, its not counting the first space only. If iS going to Is, rest of the string had to "A tEsT" little problematic kata I suppose.
Read the post below yours, they never count. You need to count by word.
ah, as I understanding we need to consider each word separately. therefore index i not 5 or 6 it's 0. ?
Yes, it starts over with each word.
This kata has a poorly worded description. It should be rewritten to make it clearer that indexing starts again from 0 at each new word
Please fix the golang tests. The spaces in some are counted in some and not in others.
Read the post below yours, they never count.
in some tests, space counts as a char, while in others, it is not counted as an indexed char please clarify this
It never counts, and it's been asked and answered below, check those posts, please.
huh? wydm it never counts? it counts in some cases and doesnt. You can see that in the 'ThIs Is A TeSt' example, you can clearly see that it ommits the first white space in the string as evident by the fact that the letter 'i' in the word 'is' is uppercased, but then why is the letter 't' in the word 'test' uppercased? if it doesnt count white space like u claim, then T would be at index 7, which is odd. Why tf is it then uppercased? The problem is with how the kata has been written.
The first character of each word gets uppercased. The conversion is for each word, not the string itself.
This comment has been hidden.
the test is little bit weird, test not passed when i hit attempt button before test button. just hit test button first and then attempt button to pass this test.
somebody there
Please fix tests for Golang.
Please elaborate on what you think should be fixed.
Tests are not correct, per the instructions. A space has an index as well, which does not change the index of the following character. So that character still has an odd or even index, regardless. If you mean every-other character that is not a space, you should explicitly say that, rather than instructing to capitalize based on odd or even index.
Please update either your instructions or the tests. The current version is not correct.
Please read the posts below, it's been discussed many times before.
Fair enough.
However, it seems the instructions could certainly be a bit more clear. It's fairly subtle.
This comment has been hidden.
Are you using 0-based indexing?
Yes
Unclear what you are seeing to be wrong and what you think is right and why. Also unclear whether this is different from the two threads right under this one.
My guess is you're not doing it by word.
The problem with this kata, there is a test value "This is test" and according to the condition it should be equal to "ThIs iS A TeSt", since every even character is uppercase, but the test is not accepted and it says that the value should be equal to "ThIs Is A TeSt', but the letter i in the word is has index 5 and it should not be in uppercase
Not a kata issue, read the instructions again or the posts below, the test is ok. You have to do it by word.
The test cases for the Python language are not correct. Please fix them. These do not follow the actual statement written on the question.
Can you elaborate what's the problem? 7000+ users solved it in python, so IDK what you see wrong that they didn't.
this point is not mentioned to completely understand the question.
It is mentioned. Several times.
the second example demonstrates it there would also be no need to mention word if it was the string-index the tests demonstrate it
Please use new python test framework.
^^
Don't forget to use ToLower() . in some tests it does not work without it .
This comment has been hidden.
Your code is very hard to read. Please use proper formatting (triple backticks + language) and post your code in reply here.
This comment has been hidden.
Please mark your post as having spoiler content next time.
This comment has been hidden.
I tried looking over it, and I think you're swapping case based on input string. That's not correct, it doesn't matter if input is all uppercase or lowercase, it should work the same. It's all about indexes.
This comment has been hidden.
Weird string case begins separately for each word, not just every character :P Does that make sense now?
yeah!, thank you.
my solution with flatMap didn't passed
function toWeirdCase(string) { return string.split('') .flatMap((item) => item.split('') .map((item, index) => index % 2 === 0 ? item.toUpperCase() : item.toLowerCase() ).join('') ).join(' ') }
And why do you think it should pass? I can see that it's wrong without running it. Not an issue.
This comment has been hidden.
I still didn't get it. can you help me out.
This kata is wrong. Sometimes it counts the space, sometimes not.
It never count spaces, you have to count the index by word.
Indeed Chrono79. My mistake.
It did count space sometime, and sometime not. Like this examples over here
toWeirdCase( "Weird string case" );//=> returns "WeIrD StRiNg CaSe"
Edit: just realised that the index need to be count from 0 for each word. Author should make it more obvious
Haskell says it only has "alphabetical characters and spaces", but it actually has special characters.
Needs random tests for Python.
^^
It would avoid confusion if the instructions stated that each word starts with an uppercase.
It looks as if the golang tests are broken, since in some test cases the space should be taken and in others not
It seems as though the tests are contradictory - in some, the spaces are counted (and the letters on either side of the space share the same case), and in others they aren't. I've coded solutions for both scenarios and neither pass all of the tests.
Spaces never count, you have to start counting again for each word. And it's been asked and answered before, check the posts below.
Yeah, but the author should clarify this in the prompt..
This comment has been hidden.
Not a kata issue, your string has a trailing space (see the tests results).
a
is a number, it'll never be equal to a range. Read thisThank you very much for explain.
In JavaScript it's great challenge. !\Thanks
nice kata
Nice twist making the case alternate reset for each word
This comment has been hidden.
whoops
No, and it's been said many times, you have to do it by word, see the in each word in the sentence:
So you start counting again with each new word.
I'd see the problem, and after seeing your comments I get it. I felt sorry if I sobrepassed my tone in this message. The 3rd TEST CASE for Python it's wrong, but the kata it's finished without any problem. It's a little mistake in the Test but it's corret in general.
I'd see the problem, and after seeing your comments I get it. I felt sorry if I sobrepassed my tone in this message. The 3rd TEST CASE for Python it's wrong, but the kata it's finished without any problem. It's a little mistake in the Test but it's corret in general.
Are you talking about the sample tests? Please, state the input, the expected output and why you think it is wrong.
ThIs Is A TeSt is the expected output for one of the tests. If we are not counting spaces, "TeSt" should be "tEsT". This is for the python tests by the way. Or if we are counting spaces, it should be "ThIs iS A TeSt". I'm still not really sure if we should be counting spaces or not.
You have to work with words, as I already said here.
I see what you're thinking Chrono79 but it doesn't say anything about indexing each word and setting relative odd/even index value. Within the string index, characters either fall on odd or even, thus 'string with all even indexed characters...' is different from 'all even characters of index of words within the string'
Golang test cases seem to be wrong
This question and test cases is wrong
Oh wow finishing this one was fun ^_^
The exspected answer is also not correct in this (PHP) test case.
Not an issue, you have to do it by word:
Arhh, sorry... Missed that part.
This comment has been hidden.
there is a problem with the test case, when i run my code somewhere else "boy" returns "BoY" but for these particular test cases, it returns "BOY".
C# Description:
I came up with a bit manipulating solution that doesn't use any booleans or conditionals.
It passed all the example test cases.
Then I hit attempt and was bummed out to see that there can be many non-alphabetical characters other than space.
Please update the description.
I'd say those tests should be removed instead.
This comment has been hidden.
i removed this test case from C# as it went against the specifications.
the expected result for some test cases are not accurate
The tests are ok, and it's been explained many times, read tlagr's post below for example.
Test case is inconsistent. Getting the following error, however they are identical strings:
I know this is a very ... very old post, but I thought I would point out that the issue is that your solution string has an extra space character at the end.
Basically
"AbC DeF " != "AbC DeF"
, which is the correct behaivor for the test case shown.not a kata issue
Go translation kumited, please check and feel free to approve or reject it!
Seems likes there's an issue with the testing. If there's a space, the characters on either side should be the same case OR if we're supposed to ignore spaces, they should be opposites. Testing is inconsistent in that even within the same sentence they have both. (for Python)
Not an issue, you have to do it by word:
And it's being said many times below. You can also check the example in the instructions:
All words start with a capital letter and then alternate lowercase and uppercase.
Fails on 'ThIsIsATeSt' should equal 'ThIs Is A TeSt' There's nothing in the instructions about splitting a word into a sentence based on capitalization or removing spaces to create a long word. It's not clear which is input and which is output.
Your function is returning
'ThIsIsATeSt'
instead of the expected'ThIs Is A TeSt'
. The first string is not the input, print it to see what it is.PHP translation kumited, can someone please check it
The rules for spaces between words are really confusing.
This needs to definitly explicietly state that the zero indexing uppercase is for EACH WORD otherwise its super confusing.
Oh my... thank you so much. Those instructions are straight up lacking!
Instructions regarding how to deal with spaces in between words were confusion. This alone caused me to waste twenty minutes. Reading back, I can see what the author intended, but this could have been made much clearer.
Test in Python are bad. Sometimes the " " counts and other times " " don't counts
You're wrong, they never count, you have to do it by word.
why the first character is lower case when it says even is upper case and 0th index is even Assert.AreEqual("Is", Kata.ToWeirdCase("is"));
The expected value there is 'Is' and you can see the first letter is a capital one.
3rd test in Ruby is inconsistent
expected "ThIs Is A Test" should be "ThIs Is A tEsT"
case doesn't alternate at "A Test" (i = 8 and 10; 'A T')
You have to do it by word.
Based on the wording for the kata description: "Spaces will only be present if there are multiple words.", having the below test is inconsistent with that requirement.
Test Failed Whitespace should work too! Expected string length 4 but was 0. Strings differ at index 0. Expected: " " But was: <string.Empty> -----------^
ThIs cHaLlEnGe iS StIlL BrOkEn aFtEr mOnThS. fIx YoUr tEsT CaSeS. i wAnT My SwEeT, sWeEt kYu.
No it's not, try reading the other posts, it's been explained again and again. Quoting myself:
The tests are inconsistent: Eg for 'LoOkS LiKe YoU PaSsEd'
00: L 01: o 02: O 03: k 04: S
05:
06: L 07: i 08: K 09: e 10: 11: Y 12: o
'Y' is odd but capitalised. Its either spaces count or dont count.
Its not an issue. You're supposed to ignore the whitespaces and restart the counter when a new word begins. Therefore every words first char is capitalised
thx to onCC for the feedback.
Description should be more clear about indexing IMO. Took me a while to realize that it starts from zero for every word.
This comment has been hidden.
Your code is wrong, check the loop condition. It's not a kata issue, use question when it's a problem with your code.
The tests lack cases when odd letters are uppercased. Some solutions, that leave the case of odd letters as is, are false passed currently.
OP's language was JavaScript. Fixed.
wrong for javascript. some test cases include the white spaces, others don't, when factoring in whether it is even or odd
Please, read before creating a post, it's been explained several times before, even in the post below yours.
Friend, Thank you for your advice. I did indeed read the posts before commenting. However, it was my understanding that these comments were for C & Python. I am speaking specifically about Javascript. Have a good day. :)
The post below yours was for javascript too (not mentioned in the post) and going further down, there is a post from tuj that claimed JS test cases were incorrect where I answered they weren't and why. Have a good day too ;) JS tests are ok, you have to do it by word.
yeah, test cases are wrong. sometimes a space is counted, sometimes not. not sure how to proceed on this one.
for example: Expected: 'LoOkS LiKe YoU PaSsEd', instead got: 'LoOkS LiKe yOu pAsSeD' //The first space, after LoOkS, index 5, is counted and lowercase. Therefore index 6, the "L" of Like is uppercase. But the second space, after LiKe, index 10, is not counted in your test and forces index 11 to be uppercase.
No, you're wrong, the tests are ok, you have to do it by word:
C translation just Kumited with random tests ;)
Holy shit all those wrong test cases. Be more careful when creating the tests. You messed up Haskell too: sometimes you didn't count space as a character and then put the wrong case on the next following character.
Test cases are inconsistent -- Unsure how to proceed :/
Language? Inconsistent how? Read my answer to the post below yours.
I think they forgot to count the spaces when doing this. Once I hit the first space in the tests everything is off by one.
You have to do it by word.
This comment has been hidden.
JS test cases are incorrect. I was able to fix the Sample one, but I can't access the "Attempt" tests.
JS tests are ok, maybe you're misunderstanding what is asked to do. Read the instructions again.
You have to do it by word.
Thanks @Chrono79. I thought it was by the entire string. Thanks for the clarification!
C# wRoNg test....
This comment has been hidden.
You have a space at the end when you shouldn't
Thank you!! :)
for the test case: "this is a test", the expected case is incorrect.
Language?
He only trained in Python, so my guess that's the language he's talking about. rohith: you have to do it by word, so the test expected result is ok, check the other examples. Always check the posts already here, been asked and answered before.
The C# test cases are incorrect and do not give correct results. Some ignore spaces when doing the case change and some take them into account.
The parameters of the c# tests are the wrong way around. The expected value should be the first paramter, the actual one to test should come second.
that's unexpected. Yes, c# was driving me crazy. thank you. I will check.
Should be fixed.
Expected: "Z DwMhPsReRf G Lw"
Expected: "ThIs is a test"
How is this even possible? The test just doesn't work!! Ignore it and move on.
What language? For C# the expected and actual values are the wrong way around.
wow... yes for c# actually. I will check. thank you so much!
Should be fixed.
I think it would also be useful to include more abstract test cases.
For example:
This at least drives home from the details that odd characters must be lower cased.
Your examples are wrong, 'this is a test' should go to 'ThIs iS A TeSt' likewise for "WeIrD StRiNg CaSe", it should be "WeIrD StRiNg cAsE"
No, you apply the process to each word, not the entire string. The description is correct.
Quote from the kata description: ...returns the same string with all even indexed characters in each word upper cased, and all odd indexed characters in each word lower cased...
Intruction or Test case is wrong: "Expected: 'ThIs Is A TeSt', instead got: 'ThIs iS A TeSt'"
"i" in "is" is the 5th index an odd number.
Look at the comments below you. Index is counted from the beginning of every word (so the first character of every word is always uppercase).
... good to know
Instructions are unclear (and misleading). To pass, the first letter of every word must be upper, and then remaining letters alternate upper/lower.
Yes, test cases are wrong for multiple words.... inconsistent, I could solve for either counting the spaces or not but within each test sentence it goes back and forth
The test case is wrong
Description is not the best... However, I solved it. You need one key insight, which is each word is treated as its own. Therefore, whitepace resets the index count. Example:
This is a Test
= string0123 01 0 0123
= indexesxDranik, thanks for the great kata! Cheers!
Test cases are broken, some times takes the spaces as part of the sentences some not
'ThIs Is A TeSt' => the 'A' and 'T' in "A TeSt" breaks the proposed algorithem.
Tests are broken. Some of them count space as character, some not.
This practice needs to simply state that every letter needs to start with a capital no matter what since there quite a few ways you can go with this.
Test case is wrong!
i don't think the case was wrong... it's just need other way to solve the case.. something like nested loop...
that's why this case called weird.. hehe
This comment has been hidden.
I'm assuming (due to lack of indentation) that you have
print(to_weird_case(string))
outside of the function in order to call it. If so, the NameError you encouter is due to you callingto_weird_case()
with the parameterstring
but this variable doesn't exist so you get an error. You don't have to include this since the testcases call the function automatically.Codewars comments support markdown and html so you are able to section your code which includes indentation using 3 backticks. Use this so that I don't have to manually indentate your code.
This comment has been hidden.
nevermind im sorry fixed the indentation and it worked! ty
This comment has been hidden.
This test case is incorrect. test.assert_equals(to_weird_case('This is a test'), 'ThIs iS A TeSt')
This comment has been hidden.
OK, this was quite frustrating as many have pointed out, but I figured out what it is asking for. The instructions should say to evaluate each word separately, meaning you apply the upper and lower case anew on each word. It doesn't count spaces, and it doesn't matter what the case of the last letter in the previous word is. You start the index count over again with each word.
Hopefully this helps aleviate some frustration for others.
Somebody should correct that instruction
poorly written instructions i have the same problem as @yk2kus
Test case still appears to be wrong.
HORRIBLE YOU CANT SOLVE IT, DO NOT DO IT
The directions should be more clear. However if you look at the examples, it's asking for each word to be indexed starting at 0. It's do-able, but I was frustrated as well.
This one kinda pissed me off. The directions are unclear. I guess this is a lession in providing what the cusomer wants vs what they explicity said :) As others have said, Make sure you are indexing every WORD not the string as a whole.
Great kata! Kudos!
This kata is broken.
To echo other users: this test is poorly designed, the test cases are inconsistent. The case of letters either side of a sing space should always be the same.
Test case was wrong, it should be for python. test.assert_equals(to_weird_case('This is a test'), 'ThIs iS A TeSt')
Index is counted from the beginning of every word (so the first character of every word is always uppercase).
Cases are inconsistent. Problems on how to handle indexes around a space. one test case expects 'Ok FiNe YoU ArE DoNe NoW'.
This comment has been hidden.
It's because of a wrong whitespace at the end of your result;-)... for example [0:-1] helps...
Java translation Kumited! Please accept :D
rejected by someone
One of the tests required that 'ThIsIsATeSt' should equal 'ThIs Is A TeSt'. Is there something wrong with the tests?
You need to read the description really closely. It says it should return the string "with all even indexed characters in each word upper cased". So there is nothing wrong with the tests =).
But maybe this should be pointed out more clearly in the description, seeing as a lot of people (me included) seem to have stumbled over it.
test cases are not correct. 'this is a test' should change to ThIs iS A TeSt.
Problem statement does not seems to be correct please help.
The problem statement is correct (but not super clear), but the sample test cases and final grader seem correct (maybe they've since been fixed?). The key thing is this part "all even indexed characters in each word upper cased." So the first character of each word should always be capitalized.
A correct solution will transform 'this is a test' to 'ThIs Is A TeSt'.
Instructions should be more clear, and there should be some random test cases for the js version of the kata..! It was good otherwise.
Javascript version of Kata could ideally include some random test cases as well as fixed tests. Furthermore, I would refrain from constructing the fixed tests directly using (your) "official solution" unless you are 100% sure that your "official solution" performs the algorithm correctly as expected.
Poorly designed test. Instructions are very unclear.
Instruction is very unclear - it doesn't explicitly say index of the letter in each word. Instead, one would assume the question is asking for the index of the letter in the entire string.
Definitely unclear, directions should explicitly state that its the index OF EACH WORD and NOT the index of the entire STRING...
This comment has been hidden.
Your "syntax" is valid, but the semantics are not. By the way, you never declare
i
.This comment has been hidden.
return
will exit the current function. Which means that your firstreturn
is the culprit.return
line is completely off, since you're missing the()
after the function's name.Since you've asked many questions on many JS katas lately, I recommend you to take a look at the Mozilla JS guide.
The test cases appear to be both wrong and inconsistant. This is true if you use the array's natural index as well if you use a counter and skip spaces.
Really just a poorly designed test.
This comment has been hidden.
I am unsure if spaces are to be ignored or not. In the given example
toWeirdCase( "Weird string case" );//=> returns "WeIrD StRiNg CaSe"
it seems that spaces are NOT ignored, but in the given test caseTest.assertEquals(toWeirdCase('This is a test'), 'ThIs Is A TeSt');
it appears that they are.Could you clarify if the spaces are to be ignored or not? Thanks!
Edit: Doh, I found the correct answer in a reply to another comment. Spaces are ignored, as it's every other character in each word.
.
The example test case is incorrect given the instructions. This:
Should actually be:
Strangely, it seems this same test is performed on the submission with the correct result. To put another way, the example tests will fail on a correct solution.
I know the example tests are just for guidance, but you expect them to be accurate, especially when the description isn't super clear.
I think the instructions might just be unclear.
Based on that test, it looks like we need to ignore spaces when determing a letter's index. In other words, every letter should be alternating upper and lower case, not every character.
I agree that test doesn't make sense based on the description.
Edit: And upon reading other comments, it seems that neither solution will pass all tests.
(JavaScript) this issue is no longer relevant
Python translation published.
Test cases aren't consistant, at least for ruby. The capitalisation for some of the expected cases misses the space, and others include the space. Note how in test case 1 you end up with capitals either side of a space, between "A" and "TeSt", whereas you end up with lower/upper case either side of "ThIs" and "Is". It isn't hard for me to put in the logic to skip spaces or not, but as it stands, these test cases are impossible to fulfil.
1 Expected: "ThIs Is A TeSt", instead got: "ThIs iS A TeSt" 2 Expected: "LoOkS LiKe YoU PaSsEd", instead got: "LoOkS LiKe yOu pAsSeD" 3 Expected: "ThIs Is ThE FiNaL TeSt CaSe", instead got: "ThIs iS ThE FiNaL TeSt cAsE" 4 Expected: "JuSt KiDdInG", instead got: "JuSt kIdDiNg" 5 Expected: "Ok FiNe YoU ArE DoNe NoW", instead got: "Ok fInE YoU ArE DoNe nOw"
"returns the same string with all even indexed characters in each word upper cased"
Oh, bloody hell, that makes sense now. A bit confusing.
Same problem here with JS. Based on the ODD/EVEN requirments. I even noticed that there's a problem in the description itself.
"WeIrD StRiNg CaSe" should be "WeIrD StRiNg cAsE"
Odd/even per word, not per string.
The description says that only alphabetical characters will be used but the random tests in the Haskell version uses special characters.
It appears map_with_index and collect_with_index are turned off. Could be wrong. But, if so, please explicitly say as much. Thanks.
I think your test case has a little problem
I think your comment has a little problem too ;). What's the problem in the kata? Also check whether the problem has already been covered by other users.
I would agree. In the instructions, you state that a passing case is "WeIrD StRiNg CaSe" which counts spaces when capitalizing even indices. However, your test case seems to ignore spaces as counting as even indices.
The problem should explicity state that each word is indexed seperately. Based on the explanation, "This is a test" should end up looking like "ThIs iS A TeSt" but the tests look for "ThIs Is A TeSt"
Yeah, this through me off until I looked at his examples, and counted the author's char index and noted their case
This comment has been hidden.
This comment has been hidden.
Please explicitly state that every word must begin capitalized.
I'm kind of a beginner, and came up with a solution without the .split, .map, or .join methods and callbacks...but I would LOVE to put these into practice, like some of the elegant solutions I've looked at.
Can anyone suggest kata that would allow me to practice callbacks and methods like these? (I looked at the best solution and understand it conceptually, but would like to try to do the same several more times.)
None of the test cases correctly test for the odd indexed characters being lowercased.
An additional test case to check for that should be performed in both the words and sentences blocks:
Oh whoops I was indexing the entire string rather than each word separately
This comment has been hidden.
My tests are passing but it won't let me submit. I even tested myself on my computers console via irb. Ruby. Hmmm...
Post a code snippet, and mark the comment as a spoiler. I, or anyone else who's here at that time, will try to help you out :)
Are the test expectations incorrect when spaces are included, or am I misreading something? The description gives the following example: weirdcase( "Weird string case" );#=> returns "WeIrD StRiNg CaSe" where the "s" in "string" is capitalized because its index is 6. But when I test my code, Test Failed: Expected: "ThIs Is A TeSt", instead got: "ThIs iS A TeSt" where the expectation is the "i" in "is" is capitalized, even though its index is 5.
Looks like that's a typo; strangely even though I'm passing the (corrected) tests it won't accept my solution :-(
The key is the phrase "in each word" in the description. The indexing should restart at 0 for each word.
That tripped me up too when I did this kata.
Ah, that's what I was missing. Thanks laoris.
thanks for the tip laoris
"all even indexed characters in each word upper cased, and all odd indexed characters in each word lower cased"
<naggermode>In fact, the opposite is true: first character (odd) must be upper cased, second character (even) must be lower cased, etc. Or you should mention that numeration starts at zero, which is an even character. I know, we're all programmers here, but people don't count from zero.</naggermode>
Thanks for the feedback! I've modified the description. Let me know what you think :)
Now the ambiguity is gone, well done!
If it's an index then yes, it starts from 0. People shouldn't really need to be told.