5 kyu
The Hashtag Generator
55,479 of 106,927AKJ.IO
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.
Really easy kata in JS
Ridiciously easy on Python, probably more in line with 6 or 7 kyu than 5 kyu.
Haskell: random tests should not be in the sample tests
woie zowie bowier this was a really easy kyu
TBH should be a 7 kyu
maybe its harder in different languages
but in python its really easy peasy lemon squeesy
SIGMAAKAINU OUT
Java Translation
Groovy Translation
JavaScript: failure messages are confusing and extremely unhelpful. For example, one of assertions complains about a missing
#
character while it checks something totally different.I got this output while doing all the tasks of this problem: Expected a Hashtag (#) at the beginning.: expected '#DoWehaveAHashtag' to equal '#DoWeHaveAHashtag' I don't understand the error; expected and equal is the same...
They are not the same, but the message is confusing because the problem is not in the hash character:
It expected the first letter of "have" to be capilalised. "Have" -> "#DoWeHaveAHashtag"
This comment has been hidden.
Your code fails this sample test:
Not a kata issue. And read this about how to properly post your code: https://docs.codewars.com/training/troubleshooting/#post-discourse
Python doesn't test inputs that only contain spaces. Furthermore, the description is at best (I think it disagrees with the ref solution and isn't ambiguous,
'#'
is not empty) ambiguous about what that should return as a string containing only '#' is not empty, and yet the ref solution says the result should be False.At least in python it is bad practice to write a function which return two different types. This function should either return empty string instead of False or raise an exception when hashtag cannot be created.
This comment has been deleted.
Please update the requirements to include cases with a leading '#' because there are none. If I wanted bad requirements I would work instead of coming here to code.
The #DoWeHaveAHashtag test in JS is broken and doesn't seem to recognize the # sign even though all other tests work.
No, it's not broken.
But you passed all the tests. What was wrong?
I'm talking about the "attempt" test, it returned a "Expected #DoWeHaveAHashtag to equal #DoWeHaveAHashtag". The submit tests work fine far as I could tell.
The test is exactly the same in both places unless you edited the sample test, backup your code, click reset, paste it and try again.
Huh. Works now? No idea, I'm certain that I was getting that error.
It's possible that you modified sample tests by accident, hence the error. Sample tests are local for you and editable (is that a word?). However, you can't modify "attempt" tests, so maybe that's why it passed.
This comment has been hidden.
No, and why do you think your code is right and the tests are wrong? The tests are fine. Not a kata issue. Read the description again.
Changing the tests to match what your function (wrongly) returns is not the way.
Ok, thank you for your response. I will cross check again.
You're making a common mistake:
Yeah, thanks for that I realised my mistake. Ive just started on this journey learning Javascipt and its a lesson learnt. Thank you Chrono, very helpful.
This comment has been hidden.
Empty line ? Changes ? Output ?
the head of each word should not be capitalized
This comment has been hidden.
Invalidated it checking it against current tests.
This comment has been hidden.
Mark your post as having spoiler content next time. Look at the strings harder, they're not the same:
The order of the tests is odd. Test 3 assumes that capitalization is already implemented, which is only expected from test 6. Test 4 is arguably easier than 3 and should probably be run first.
It is a good exercise for kata 5-6
In the description, it says:
While implementing my solution in Scala, I initially returned
"false"
as a string for this case. However, the tests were expecting an empty string instead. I suggest updating the description to specify thatfalse
should be represented as an empty string in the output.This comment has been hidden.
Add some console.logs to your code to detect the bug in it. The error comes from word being an empty string.
Thanks for the answer. I checked, refactored my code and changed the join for reduce method to complete the challenge. The problem was the space between the words.
I think there is an issue with a basic test ("testThatSomethingShouldHappen") request. The function should reject strings longer than 140 or equal chars. This request wishes to see the string "#CodeWars" but the input string is larger than 140 chars:
$this->assertSame('#CodeWars', generateHashtag('Code' . str_repeat(' ', 140) . 'wars'));
I'm using PHP on this Kata
The final result has no spaces, so no, it's not longer than 140 chars. Not a kata issue.
The final result (#CodeWars) not the input should be less than 140 chars.
The question says "If the final result is longer than 140 chars it must return false". But, the "Too long" part (below is JavaScript version of the test code),
just gives me 140 "a"s and does not return "false". I think that the question should be "140 chars or longer".
With the hashtag, it has 141 chars. Not a kata issue.
Ah. Makes sense.
Hi. I've been running into the same error with the Looo...ong Cat test and another one where the final hashtag is longer than 140 characters. According to the tests I should be returning False instead of whatever it is I'm returning. However I've been debugging my code in pycharm to see what was going on and what I was returning... my code IS returning False for those cases yet here it is not? I'm not sure what's going on.
EDIT: Nevermind I'm dumb. I don't really use twitter (ig it's X now) so I thought the length of the hashtag was counted after the "#" so I was substracting 1 to the length of the final string.
arreglen el copilador, en local me funciona
My favourite kata ever! Thank you very mutch! Lllove it!
This comment has been hidden.
This comment has been hidden.
Seems too easy for a 5kyu
I keep rewrite my code over and over again. I do not use touppercase, (though, why?), I keep have right answers in my browser console, and I keep have errors when trying to test it. Different errors. First version apparently didn't like touppercase using, ok, I changed it. Second version didn't like an replace method (not sure but still, it was adviced in discussion), I changed it too. Third version didn't like an one word case test - expected false to equal '#CodeWars'. But I do have '#CodeWars' as a result in browser console! I also do not check string.length too early, and still, errors.
The test for this cata is written POORLY and BUGGY! Why does it reject touppercase method and keep throw an error? It also reject fromCharCode(charCodeAt) method and also keep throw an error.
What. Is. Wrong. With. This. Cata???
If your test code do have problems with certain methods, then may be you'd mention it in cata conditions not to use this and that?
The tests have no problem with either method, it's your code that's trying to use them wrong, read the error message:
undefined
doesn't havetoUpperCase
method, that's a string method. Debug your code, add someconsole.log()
s to help you with that. Read this: https://docs.codewars.com/training/troubleshootingCurrently, your code fails this sample test:
Undefined is valid only when it's "" in test - empty string has no length. So I add check on string.length with break to quit code execution: switch (str.length) { case 0: return false break} ABOVE toUpperCase method line, so it had to be irrelevant wether toUpperCase were used in code in lower lines or not.
Why have testing keep throw an toUpperCase error when I quit code execution before toUpperCase method has been applied?
I already told you exactly which sample test your code is failing, use Pythontutor or other IDE to debug your code step by step and see what's wrong with it. Don't chain methods until you properly understand what they return in each of them, pull them apart and log what they return, you'll find out what's wrong with your code easier that way.
This comment has been hidden.
Description does not ask you to return
equal
. It specifies to return the modified string except when the final string is longer than 140 chars / empty , or when the original input is already empty.Your code, OTOH, returns
equal
for final strings of length 140, modified string for lengths less than 140 andFalse
for other cases.Problem is not ask us if it is equal to 140 or not. if len(nick) without # is 140, it must return False too.
This comment has been hidden.
Should look at the resulting length.: False should equal '#ABbCccDdddEeeeeFfffffGggggggHhhhhhhhIiiiiiiiiJjjjjjjjjjKkkkkkkkkkkLlllllllllllMmmmmmmmmmmmmNnnnnnnnnnnnnnOooooooooooooooPpppppppppppppppQqq'
The test keeps failing with the error message below. The string above is also 140 chars only. So, why the testcase is not passing when I have the condition to test the string length.
I'm having the same problem, perhaps you could make a specific statement that checks if it is this string and return false? But for real, not sure why this is happening.
hi how did you solve this problem
Same problem
I solved it with using replace with regexp. However I am still confused why there was error with toUpperCase function called. There is only string as input as I need to dig this deeper.
Traceback (most recent call last): File "/workspace/default/tests.py", line 1, in from solution import generate_hashtag ImportError: cannot import name 'generate_hashtag' from 'solution' (/workspace/default/solution.py)
What should i do?
This comment has been hidden.
Why is your solution named
to_camel_case
?How should it named?
It should be named
generate_hashtag
. It's in solution setup:can anyone please tell me why do i keep getting this same error?the error, Still an empty string: expected '#' to equal false
You are getting the same error all the time because you have the same bug all the time.
We do not know what bug it is, because we do not know your code.
What does your solution return for following test case? What should it return?
generateHashtag(" ".repeat(200))
the output is #
nevermind i got it :]
This seems to be a very poorly written test. A lot of the conditions are only made clear in the test cases, and the description explicitly states that the method should return false in some cases and String in others, yet the method return value is String. It's not clear that it actually means it should return an empty string when it's invalid, unless you look at the tests
can anyone help me please the compiler for some reason keeps saying that it can not convert my string to upper case
Try logging what
str2[i]
contains after you split it. You should know what you're doing wrong from there.This is an issue of your code, not the kata. So please, next time you encounter error from your solution and you want to ask in discourse, don't flag it as issue.
Resolved.
This comment has been hidden.
For some reason it doesn't recognize str.length. It always skips over my statement and always gives back "false". In my own IDE it works perfectly fine.
Not true, and your current code works, so it must have been a problem with your code and not a kata issue. Closing.
Ruby: function name should be snake_case
Fixed in this fork
This comment has been hidden.
Close enough, but you missed this part
If the **final result** is longer than 140 chars it must return false.
действительно ли из 'Codewars' нужно получить 'CodeWars'?
No, but:
Тоже самое меня удивляет .... Мде. Вроде решил, а где-то маленькие буквы нужно сделать большими. Без какого либо смысла
This comment has been hidden.
Close enough, but you missed this part
If the **final result** is longer than 140 chars it must return false.
This comment has been hidden.
The hash symbol counts towards the message length. Not an issue.
I see, thanks for the response!
Works in node console returning false for over 140, but fails tests here
OP fixed it
please, wha is OP??. i have the same issue
I keep getting this failed test case and I dont know how to solve it -> Too long: expected '#Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa…' to equal false
OP solved it, closing
This comment has been hidden.
seems to me like wrote something by guessing. why would it work? like lego, things fit certain ways.
OP solved it, closing
This comment has been hidden.
Whatever I do I keep seeing error: "Should look at the resulting length: expected false to equal '#ABbCccDdddEeeeeFfffffGggggggHhhhhhhh…'"
Error message contains not enough information to understand what is wrong.
The task itself lacks details and unambiguity, e.g. I must check the length of raw input string or "condensed" ? trimmed ? single spaced ? Why string with a space is called "empty" (in tests) ? "It must start with a hashtag (#)." --- is about result or input ? How result can be empty string if it MUST contain '#'.
This kata reminds real life situation when task is given partially and you have to GUESS what to do... sorry for much text, i wanted to relax doing katas but something went wrong)))
I believe the issue is mainly caused by badly formulated requirements.
Do that and you won't have a problem with that test, why do you say it hasn't enough Information about what's wrong?
A hashtag has no spaces, so it's not the input with a space which is called empty, it is the result:
Also you don't check the length of the input:
Please read the description again.
Should look at the resulting length: expected false to equal '#ABbCccDdddEeeeeFfffffGggggggHhhhhhhh…'. Please someone help me with this error
That's a problem with your code, not a kata issue. Read the posts below, like this one: https://www.codewars.com/kata/52449b062fb80683ec000024/discuss#64e1f129c379c7005b08ea72
Read this too: https://docs.codewars.com/training/troubleshooting
Thank you, I've finished working on it. By reading all the discussions, also the error, and I enjoyed it.
Should look at the resulting length.: False should equal '#ABbCccDdddEeeeeFfffffGggggggHhhhhhhh......'can someone explain for me this bug pls
I also only had this error, try if you add # to return, add # it in the code, it helped me (it just may not compare # if if is written in return in one line)
the intructions missing the point that first letters should auto capitalize.
What's missing?
I enjoyed this one, thank you. One small issue is that on the Python version, False is written as false with a lowercase f in the description. At first I was a bit confused, thinking maybe the tests were expecting us to return a string saying "false" if there was a problem with generating the hashtag. In other words True and False are capitalized in Python.
Just a small quibble
Yes, but description is shared amongst all languages and making a code block only for Python is not needed here, you can see false and False are booleans, and a string would have quotes around it. You can also check the sample tests when in doubt.
There is an error with the sample cases, it was written as "assert.strictEqual(generateHashtag("code" + " ".repeat(1function generateHashtag (str) {" but should be "assert.strictEqual(generateHashtag("code" + " ".repeat(1))function generateHashtag (str) {". This causes an error with the syntax.
There is no error in the sample tests, you probably modified them without noticing. You can press
RESET
to reset the trainer to the initial state.I've tried multiple solutions, encountering errors until I believed I had found the correct one. However, when I attempted it, I received this error: " Should look at the resulting length: expected false to equal '#ABbCccDdddEeeeeFfffffGggggggHhhhhhhh…' ". So my code isn't good enough or this is an issue. Assuming the result is a sum of the letters of the alphabet plus the #, the length of the response should be greater than 140. Therefore returning 'false' would be the correct thing to do. Please let me know if I am wrong.
You're wrong. Not a kata issue. Read the error label again, your code doesn't do that.
Assume nothing, print the input.
User 1: Please let me know if I am wrong.User 2: You are wrong.User 1: REPORTED!EDIT: So apparently the report was done by another user, and not by the OP. I got confused.
to OP: re-read again the description .... it says if the "Final" result....
I didn't report!! I just seen this. Anyways, thank you all, I'll keep trying.
Hmm could someone spoon feed this to me? I can't seem to get around this. The 'final' string is 169 characters long, why should that not be returned as "False"? 140<169
There should be tests of single-character strings like
#
,A
anda
to invalidate certain solutionsThis comment has been hidden.
You can
print()
the inputs to your function. Also your shown code seems to work for me.I've got this test not passed: Should look at the resulting length.: False should equal '#ABbCccDdddEeeeeFfffffGggggggHhhhhhhhIiiiiiiiiJjjjjjjjjjKkk But i'm sure that my code is working, so there is a problem with this test. please correct it
The tests are fine:
Your code has a bug. Read the error message again and check what your code is doing.
This comment has been hidden.
Please mark your post as a spoiler and use appropriate markdown formatting when posting code. See https://docs.codewars.com/training/troubleshooting#post-discourse.
Yes. After formatting your code, I was able to run it just fine. Make sure that:
RESET
button to reset the trainer)The result in my IDE seems to be ok. "Do We have A Hashtag" and "Hello there thanks for trying my Kata" transforms into "#DoWeHaveAHashtag" and "#HelloThereThanksForTryingMyKata". The strings with length > 140 return false. But tests failed with "Cannot read properties of undefined (reading 'toUpperCase')" error. What could be the reason for this behavior of the algorithm?
Print the input. Your code fails the second sample test.
I encountered this problem. It happens when the algorithm attepmts to call toUpperCase on an empty string. Several of the tests contain empty strings to force you to work around this.
returns this error: Still an empty string: expected '#' to equal false - though the # element is required in the result
No, the expected result is false there.
expected false to equal '#CodeWars' even if the code works just fine...
Not a kata issue, please check again the requirements for the kata, especially:
Your solution is incorrect - debug it.
Not a kata issue. See https://docs.codewars.com/training/troubleshooting#post-discourse.
in description we have condition that if final result LONGER than 140 chars it must return false, but we have no condition that if final result EQUAL 140 chars we have to return false too.
Final results with 140 characters are valid. Are you counting the character
#
?Anyway, not a kata issue.
This comment has been hidden.
That's a problem with your code, not a kata issue. Print the input, debug your code.
Agree
Why the difficulty of katas is SO different every time? It was nothing, compared to other 6 kyu tasks I've solved.
Cause when the kata still in beta version. it Given Score by each person. So everyone can give for different difficult parameter based on person. Its subjective.
there has also been a significant rating deflation over time. this kata is from 2013.
expected #dowehaveahashtag to equal #dowehaveahashtag can somebody tell me the difference im just a silly person
The
ISSUE
label is for provable kata issues. Please use theQUESTION
label when asking for help. See https://docs.codewars.com/training/troubleshooting/#post-discourse.That is not the assertion message you get:
This is the assertion message that you get. Case matters!
Not a kata issue.
.
why I can not use charCodeAt() or toUpperCase() javascript functions
You can, many solutions do, mine does use one of them, you must be doing something bad. Please don't raise an issue when your code is not working, but rather a question. Issue means a provable flaw in the kata's design. I advice you to read this to learn debugging your solution and ask for help more efficiently: https://docs.codewars.com/training/troubleshooting/
This comment has been hidden.
纯煞笔
This comment has been hidden.
OP solved it, closing
expected false to equal '#CodeWars' even thought I I'm returning '#Codewars' as It should be right?
Your code incorrectly returned
false
for the following test case:Not a kata issue. See https://docs.codewars.com/training/troubleshooting#post-discourse.
C# translation ready! Please review and approve.
how is this kata for 5 kyu? it's easier than a 6, 7 kyu...
Totally shitty, sucks....
Why is this 5 kyu? A lot of sixes is harder that this. I dont't get it or ?
Maybe it is not hard
This comment has been hidden.
The string is 140 characters long. You should only return false if it is longer than that.
My code is succesfully completing all random tests, if I try to put this string and make on local - I have everything ok.
What?
The initial string has a lot of white space and is 173 characters, but the resulting string after making it into a hashtag is 140 characters long. My guess would be that you're rejecting the hashtag based on the initial string length, and not the actual hashtag length.
Should look at the resulting length: expected false to equal '#ABbCccDdddEeeeeFfffffGggggggHhhhhhhh…' what's wrong
Your code returned false when it should have returned the other value in the error message. Your current code works, so you fixed it.
This comment has been hidden.
Not a kata issue. See https://docs.codewars.com/training/troubleshooting/#post-discourse.
See https://docs.codewars.com/training/troubleshooting/#works-but-no.
This comment has been hidden.
You don't so the capitalizepart in your solution (note
have
vs.Have
in the assertion message).why are they asking me for random tests?🕸
This comment has been hidden.
Mark your post as having spoiler content next time, please. Print the input or check the sample tests to see which input makes your code fail.
Thank you. I am sorry. I understood my mistake. I am a bit new in comments)
You're welcome.
Is this kata broken? Everything works fine in the IDE, but for some reason the site says that there are errors. I have checked all the tests and everything is correct
works fine, check that you have the code formatted correctly
No, it isn't:
This comment has been hidden.
Hello, please read this: https://docs.codewars.com/training/troubleshooting/#post-discourse and mark your post as having spoiler content next time.
My appologies. As the code does not work, it slipped my mind that it should be tagged as spoiler. I will do so next time.
For some reason the code formatting is being lost when I post. The code is in python though.
Use code formatting, it's explained in the link I gave you. See the example for Python, you need to use backticks:
Don't leave spaces before the backticks or the code will be seen as a single line.
This comment has been hidden.
should_capital != should_captial
you have a typo in the var name.Such a silly mistake on my part. Thank you for your help and patience.
You're welcome.
this test is broken my code work well in IDE but as I test here ther that issue with "Codewars" he expect what ?????
No, it's not:
Read the posts below, like this one
IMO too easy for 5kyu. Should be 7.
I guess tests should also check fo boundary values:
I am returning false i str is empty
then why my code further execcute it should return false. however it's working fine in console not here
Your code is failing this test:
my code works completly in console, but here does not working
so... it does have hashtag obviously. checked it 1000 times on codepen. works perfectly. not sure what the issue is here
This comment has been hidden.
Your current code works, so, probably it was a problem with your code and not a kata issue. Closing.
I liked this one a lot, nice job
This comment has been hidden.
Your current code works, probably your previous code was failing this test:
Not a kata issue.
Expected a Hashtag (#) at the beginning.: expected '#DoWehaveAHashtag' to equal '#DoWeHaveAHashtag'
Look here:
hey i check that the string is not empty and it keep saying return false if(!str || str.length < 1){ return false; } this is not enought for checking empty strings? cheers!
A problem with your code is not a kata issue, that line is not in your current code. In your current code you create a new string with a starting value of
"#"
so it will never be empty.This kata is way too easy for 5 kyu - it should be around 7 kyu instead.
Ranks can't be changed.
No random tests for Javascript.
Please fix the 148 white spaces i tried regex and trim() and it's not working
There is nothing wrong with the test, fix your code.
I apologize maybe there is something wrong with my code but can i ask? why the trim() is not working on 148 characters of string with whitespaces in "code (whitespaces) wars" you think you can help me on this one?
Because it removes spaces at the start and at the end, not in the middle: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim
I tried replace(" ","") too not working
Because that won't replace all occurrences.
I'm so confused i have no idea how to fix it. But thank you for explaining it man.
Maybe it is necessary to add the condition of having only one "#" in the entire output str (at the beginning of the hashtag). Because in my tests I've got resal like this - "#TheABC#quickBro"
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Your solution crashes with one of examples:
" Hello World " => "#HelloWorld"
This challenge has incorrect tests for JavaScript. In the instructions, it doesn't state that strings just with a hash(#) should return false.
That's not true, your code is wrong. Your final var will never be empty string if you initialize it as #.
Thanks, I understand. I think it would be benefical if the instructions included this info.
I don't understand the following test: Test.assertEquals(generateHashtag("a".repeat(139)), false, "Still an empty string") If a is repeated x times, it's not an empty string. What am I missing?
You have edited that test, because it should be like this:
Backup your code, click reset, paste it and try again.
Thanks, I somehow was able to pass the challenge!
This comment has been hidden.
Mark your post as having spoiler content next time.
Sorry, I dodn't know how to make Spoiler. Next time I'll fix it. Where is it?
It's a checkbox below the textbox where you write these posts, it says "Mark as having spoiler content". I've already marked it for you in the first post. Use it when you post code or some comment with spoilers in it. Read this: https://docs.codewars.com/training/troubleshooting#post-discourse
This comment has been hidden.
The following lines of code need to be indented (so the i is corresponding to the loop above): for z in range(len(i)-1): result += i[z+1]
OP solved it, closing
Hey! I think a wording in the description is a little wrong! In one of the test cases provided,
"a".repeat(140)
was marked to be equal tofalse
, while the description read "If the final result is longer than 140 chars it must returnfalse
." I think the mathmatically correct way here is "If the final result is longer than or equal to 140 chars it must returnfalse
."No, because you forgot the hashtag there:
This comment has been hidden.
Have you tested your function with
"code" + " ".repeat(140) + "wars"
as input there too?Oh now that is curious. I see the issue, thanks!
This should not be 5 kyu, it is easier than that.
Ranks can't be changed! (Especially for old katas with high completions)
after weeks suffering for barely completing a kyu 6 kata this one really feels off. Should be a 7 or 6 kyu max.
How come i only got 8 honor for this? Did mods deem this too easy for a 5 kyu? If so, they should change the kyu rank.
Ели вы создаете такой тест, будьте доры указать коректо условия и требования!!
This comment has been hidden.
Backup your code, click reset, paste it and try again.
@mponsclo_ it's because you have a spelling mistake in your function name:
def generate_hastag
should bedef generate_hashtag
<- note the 2ndh
in hashtagIf you work on another IDE then paste into Codewars make sure you get the right function name from the default code setup as @Chrono79 says
This comment has been hidden.
Seems you forgot to return result
well it works on my computer
I've: Still an empty string: expected undefined to equal false, but my code works on my VScode and return false
I created a Swift translation of this kata, any chance for approval?
The description asks to return false when s is empty but in the tests "" is the required return value
Duplicate issue
"expected false to equal '#CodeWars'" But code works in console or .js file on pc, weird
Hi,
not an "issue", a "question".
This might help you: https://docs.codewars.com/training/troubleshooting
cheers
i have the same issue
also having the same issue with #Codewars
should not be 5
Honestly, felt a bit too easy for a kyu5 challenge.
share code if you done it correctly please
The instruction said "If the final result is longer than 140 chars it must return false." But in my solution it should've been "is equal or longer than 140 chars". Or maybe explain that 140 chars includes the hashtag ("#") so that it's more obvious
The hashtag is included, not a kata issue.
Had the same problem
This comment has been hidden.
Hi; there are a few things not working with your solution, but the main one is that you are
print
rather thanreturn
int your solution.Furthermore, currently you are printing
for j in ls
several different times, whereas you will need to find a way toreturn
only once - maybe by building up an output string then returning once it is finished. Hope that helps you get started on debugging!Scala description needs update: the description claims you must return false for invalid input, but the tests expect an empty string.
Returning empty string is more sensible behaviour, please update the description to reflect this.
Hi just wondering if its my code or the test with the issue, I keep getting the error:
TypeError: Cannot read property '0' of undefined at generateHashtag (test.js:11:26) at Context. (test.js:25:19) at processImmediate (internal/timers.js:464:21)
Yes, it is your code. Add some
console.log
s to debug it. It's failing the first sample test btw.I love when kata correlates with actual tasks!
This comment has been hidden.
See the first H.
This comment has been hidden.
See the first H.
oooof, thanks :)
This comment has been hidden.
Not a kata issue. Your code is testing the input's length.
Python fork for review
Updates to new testing framework
Resolves issue raised by user @dongjin2008 : removes a fixed test which causes tests to fail ungracefully if user's solution is not of type
str
Improved random test generation so that it does generate strings where expected answer is
False
Please close issue below if the fork is approved, and reply to user. Thanks!
#Reviewed and #Approved
The test case shows error TypeError: 'bool' object is not subscriptable
(user @dongjin2008 is working in Python)
Hi - I looked through the tests to see what is happening; indeed this happens because of bad test design (in my opinion).
There is a test:
test.assert_equals(generate_hashtag('Do We have A Hashtag')[0], '#', 'Expeted a Hashtag (#) at the beginning.')
which tries to access the
0
th element of the user's returned solution - if the user incorrectly returnsFalse
orTrue
while developping their solution, the tests fail.I suggest removing this test, or at least using a type check or try/except when testing the users returned solution.
I will update the tests now to new framework, and reorganize the tests - I will reply to this comment with the updated fork soon.
Hi @dongjin2008 - the Python tests have now been improved and this should no longer happen. If you return to this kata and get the same mistake, please click "Reset" to update the kata settings but save your code first because it will be deleted
Hey @KayleighWasTaken , we should probably edit the description for the Scala language to specify that we should return empty strings rather than false when the resulting string is empty or longer than 140 chars.
This comment has been hidden.
Print the input, see where you're using toUpperCase in your code, discover what's wrong and fix it catching it before it reach that line.
Or comment out the sample tests until you find the one your code is failing. Answered, closing.
Scala translation
When approving can you leave a non-empty comment so that I get notified, please? <3
there returns 'undefined', when " ".repeat(138) => it looks like 'codeundefinedundefinedundefinedwars'
TypeError: Cannot read property 'toUpperCase' of undefined
but the code is working perfectly in the browser consoleWell ok, but it still doesn't work here, because your code is flawed. Check it again with str of a few spaces.
Hi, who could helps me with '#CodeWars' error, should return false, I returning that value, but tests didn't pass(JS ). I could share link on CodePen.
Hi, there are lots of tests with a similar input so it's hard to tell which one you are failing on: try printing the input so you can see what the string being passed to your function actually looks like:
https://docs.codewars.com/training/troubleshooting/#error-messages-and-printing-your-inputoutput
Then you can "debug" manually, by comparing your code to the conditions given in the description. For example maybe your code is failing due to whitespace, capital letters, empty string etc.
How do I add letters to a capitalized letters to a string and keep them capitalized?
This comment has been hidden.
That your function returned false instead of '#CodeWars'. To debug your code, print the input yourself, it's a 5kyu kata after all. And it's a sample test, you can see the input directly. Alse read this:
This comment has been hidden.
Hi, welcome to Codewars.
Please don't use issue tag for problems with your code - that is reserved from serious problems with the kata itself. You can use Question instead.
For your code - you are using
lower
incorrectly: in your statementi=i.lower
try writingi=i.lower()
and your code should work (at least, it should not have the error anymore).By the way - in case you are new and didn't know this - you can use the
print(variable_you_want_to_debug)
inside your code to see where things are going wrong.For example:
Thanks for your help and advice.
I'm getting the same issue as everyone else. The output matches the output, but it is not working.
I tested your code, and your function's output does not match the expected output
In this example, the "H" in "have" is not capitalized.
This comment has been hidden.
I am not exactly sure what your test presents, but it behaves as expected. With your test, I get following:
If you mean this test case:
Expected: '#CodeWars', instead got: false
, then your test unfortunately does not diagnose this input correctly. Try following code:and notice how the input for this test case is neither
'CodeWars'
nor'Codewars'
nor'codewars'
nor'codeWars'
.If I did not get correctly what your issue is, or you still think there are problems with tests, please post your whole code here, or come to
#help-solve
channel at Codewars Discord so we could help you more!Read the post below yours, the tests are fine.
I'm also having an issue with the test case: "Expected: '#CodeWars', instead got: false". I'm using JavaScript and the code does return #CodeWars in VSCODE. Do I need to paste the code here?
Not a kata issue, that's a problem with your code:
The problem is that when I run the same code in VSCODE (same input and function) it returns the correct answer (#CodeWars), but here it returns false
generateHashtag("code" + " ".repeat(140) + "wars")
Is that the input?This comment has been hidden.
input = 'Codewars'
That's not the input that makes your code fail, it's the one I posted above. To check what the input is, print it to the console in the first line of your function.
Oh! Thanks a lot
I'm pretty sure this is a problem with my code as so many others have done it but this error just made me smile. Expected a Hashtag (#) at the beginning.: expected '#DoWehaveAHashtag' to equal '#DoWeHaveAHashtag' May or maynot be an actual issue.
Not a kata issue.
Nice spot. Thanks
This comment has been hidden.
Probably because you're validating the input's length, not the final result's length.
This comment has been hidden.
This comment has been hidden.
I got this error. Expected: '#CodeWars', instead got: false.
Although everything works in my editor, the code fully meets all the requirements...
I wrote in JS and tried different versions...
Wasted time...(
The tests are correct, and not your function.
Same Here In JavaScript
i Passed the test it's not a kata Issue
I think the test is incorrect I too receive: "expected false to equal '#CodeWars' " which is not really what happens. I think the test needs some correction. I used JavaScript
Read this: https://docs.codewars.com/training/troubleshooting/#print-input or select Node 8 to see better error messages, it's a problem with your code, not a kata issue. The tests are fine.
there is nothing wrong with the test. the test should be a guilde line for u to follow.
This comment has been hidden.
nice kata!
D translation
There aren't any test cases that have a leading "#" in the input. (That also makes the expectations a bit ambiguous, so that could be clarified as well.)
Lua translation! (author is inactive)
Approved
Thank you!
Expected a Hashtag (#) at the beginning.: expected '#DoWehaveAHashtag' to equal '#DoWeHaveAHashtag' Is this a bug ?
You missed the Have capital H there. Not a kata issue.
my bad again @@
" expected false to equal '#CodeWars' " .... I copy/paste the same code into VSCODE it just works there ... really frustrating
Handling issues with insufficient amount of details is also frustrating ;)
What language do you use? What is your code? What did you try? Why do you think your solution works in your VSCODE, maybe it does not?
Please see if the troubleshooting guide has any useful info.
thural, your current code works. Closing the issue.
The tests dont match the description. It asks that all results longer than 140 chars should return false yet in the tests it expects us to delete duplicate words from the input and return a true value.
Where do you see you need to remove duplicate words? I solved this kata in 4 languages and didn't have to.
In this test case:
Nevermind, I'm wrong :)
This comment has been hidden.
Well I dont think so, in practice section filter to 5kyu and sorted by 'Popularity', you can see easier 5kyu katas there.
The tests don't seem to check all the conditions. Noticed couple of solutions where the INPUT string is checked if it's length is greater than 140 characters and not the FINAL string, yet those soltuions passed the tests. But the input string is allowed and can be greater than 140 characters, the condition is for the final string to be with max length of 140 chars.
You are most probably wrong, and however, since you don't provide any example, language or proof, this is not to be considered an issue. Please read carefully the documentation and don't raise issues so lightly in the future: https://docs.codewars.com/training/troubleshooting/
This comment has been hidden.
Please use a spoiler flag, you are giving away solutions. It's clearer now indeed. Random tests have a very low probability to generate strings with great amount of whitespaces like you are mentionning. Yes, it is possible the kata would be better testing such edge cases. If you want to be productive then give clear examples like you have done, and better still, concrete proposals to improve the tests. The great majority of issues raised are actually not issues but mistakes of the original poster, that's why it is important to give concrete arguments.
I'm sorry for not marking it as a spoiiler, I'm new to this and am still getting used to it. Glad we understood each other in the end.
I wrote a fork for the Python translation that addresses this oversight (Kata author is inactive).
Factor translation (author inactive)
Approved
When I attempted it and it worked it wouldn't let me submit it. Has this happened to anyone else?
Your code throws an error:
This is not a kata issue (= a bug in the kata).
thanks for wasting my time with obscure statements
This comment has been hidden.
Please don't post solutions in Discourse.
Too bad replaceAll is not supported (js)
This comment has been hidden.
this can help
mistakes in your code do not make up
kata issues
. tag comments with kata issue only if you have found a bug in the kataI found this one extremely frustrating because the error codes were really misleading
This comment has been hidden.
Never assume your code not working is a kata issue, unless you undoubtedly prove it (and you obviously didn't).
This is the test:
So: no, if your function fails this test, it doesn't return
"#Codewars"
with"Codewars"
parameter.Please read carefully the documentation: https://docs.codewars.com/training/troubleshooting/#post-discourse
Yea, that's the problem, I've tested it everywhere, codepen, scrimba, local IDE etc, they all return "#Codewars"
Look carefully at the sample tests, your code is not failing on the input you believe.
Code works on Repl exactly but for some reason the code refuses to work in Codewars. Tests that it's passing through won't work and not sure why :( (says it fails at the .toUpperCase portion)
(author is inactive)
This comment has been hidden.
the code is correct error in the task
The tests are good, your code is incorrect.
This comment has been hidden.
" ".repeat(200)
is just a string of spaces. Your function should returnfalse
in this case, since the output would be empty, which it doesn't.OP solved it, closing
This comment has been hidden.
Your code fails the second sample test:
generateHashtag(" ".repeat(200))
should returnfalse
.This comment has been hidden.
Please use a spoiler flag when you post code, I put the flag for you on your two latest posts. This code does return
false
and printsalarm
on the first test. Just look at the logs, it fails on all the other tests, where it returns nothing (=undefined
):generateHashtag('') // alarm
console.log(generateHashtag("")); // alarm // false
console is an global object and log is its one of the method. It prints only the parameters passed on console. read more about console here >> https://developer.mozilla.org/en-US/docs/Web/API/console
The message 'Still an empty string: expected undefined to equal false' matches the test
Test.assertEquals(generateHashtag(" ".repeat(200)), false, "Still an empty string")
, which is a string formed with 200 spaces. In this case, the hashtag should be empty (there is not a single word), so you must return false.This comment has been hidden.
This does work on the first fixed test.
This comment has been hidden.
Your code returns
False
, and tests expect a hashtag. This test design is quite bad (tests should handle this more properly than by crashing, and however the type return should not be mixed), but this kata is old and we have to do with it.instructions ask to return 'false' if more than 140 chars or if it is empty, but test need False to pass
If you mean false/False, the description is shared amongst all languages.
closing
Not difficult enough for 5 kyu, should be around 6 or 7 since it's just string slicing/indexing
probably because you use python... Kata's rank can't be changed
Solved, someone?
kata ranks once set can't be changed for any language
if you feel that a kata is underranked, it may be because many languages share the same rank, so what's easy in python may not be as easy in other languages
and this is not a suggestion :P
At least in Javascript, this was a bit more involved and felt like a 5kyu.
Kinda had to cop out on validation on this one... since it ending up ignoring my conditoional at the top of the function block and continued execution... but it does work
COBOL translation (author inactive).
Approved
Description of the task is not exhaustive. And not correct(If the final result is longer than 140 chars it must return false.)
More than 40,000 persons (and I) solved this kata following the instructions with no problem.
piliponful: Why do you say so?
I can see how much people passed it, I didn't ask for that info. It doesn't make description correct, does it? @akar-0
Chrono79: Because longer then 140 is > and in test cases there are >=
Which language are you refering to? There are currently 7 of them. When you post an issue please provide concrete arguments: logs, inputs... See there: https://docs.codewars.com/training/troubleshooting/
piliponful: are you including the hashtag?
Chrono79: ooohhh, you're right, that's why I'm counted wrong. Thanks. All good with tests after all
My code works in the console but doesn't pass the test here. I think this is broken.
18K solvers in JavaScript disagree.
Not to be rude, but ~43.000 solutions and you conclude that if it doesn't work, it's because the kata is broken?
This comment has been hidden.
Could be. But let users solve the kata on their own (I marked your comment with a spoiler flag).
Seems like the first test is corrupt? When deleting it, I can pass without getting an error
Seems like now it is working again.
This comment has been hidden.
Do you mean to say, how
" "
+" "
is still an empty string?It's because it's two (or more) whitespaces together, the result of above just being
" "
(now two whitespaces).Since the task is to remove spaces to make the result a proper hashtag, it's probably safe to assume we should remove all spaces no matter how many might be in between two words.
TypeError: str.replaceAll is not a function at generateHashtag (test.js:10:14) at Context.it (test.js:31:19)
works in chrome console
#CodeWarIsNice!
This comment has been hidden.
This comment has been hidden.
All conditions are met. Tests for variants not described in the condition. The author just mocked, such tasks should be deleted
This comment has been hidden.
I'm not sure if this has since been resolved, but as far as I could tell, the reason is that there is no input that required forcing anything to lowercase. I passed only by ensuring the first character of each word was capitalized.
To reiterate, it's not that the tests require it, it's that the test inputs don't have any uppercase letters embedded in the words anyway. So the problem requirements are accurate.
There is currently an example of this in python: one of the test cases has 'CodeWars is nice' as the input with the expected result '#CodewarsIsNice'. When this test is failed the message 'Should capitalize all letters of words - all lower case but the first.' is given.
This was easy for 5 kyu level. Could be 6 or 7.
All requested is done. I think is bad kata.
Broken Nvm, wrong information about length of the words. I also dont think this is 5ky. 7 kyu are even harder.
Он должен начинаться с хэштега ( #). Во всех словах первая буква должна быть заглавной. Если окончательный результат длиннее 140 символов, он должен вернуть false. Если ввод или результат представляет собой пустую строку, она должна возвращаться false
Moe решение отвечает этим требованиям. Почему при прохождении тестов выясняются дополнительные требования?? Это уже не первая такая задача... Иногда приходится весь ход решения менять, потому что кто-то не прописывает все условия, а затем требует то, о чем и речи не было. Такое себе ресурс...Тому кто писал хочется заехать в глаз и побольнее. Ненавижу отсутствие конкретики. Знаю таких людей, они отвратительны.Задача решена. А осадок остался...
Поддерживаю!!!!
хорошая задача и хорошие условия, есть пара ловушек, но это 5 kyu так что... а конкретика вещь хорошая, но в жизни встречаемая редко, учитесь плыть в мутной воде
TypeError: Cannot read property 'toUpperCase' of undefined at str.split.reduce (test.js:9:24) at Array.reduce () at generateHashtag (test.js:8:8) at Context.it (test.js:20:19)
Works on Chrome Console but it doesn't in the embbebed console. Trying to use a toUpperCase of a string var inside a reducer
That's a problem with your code (that we can't see). Read this: https://docs.codewars.com/training/troubleshooting
clear the whitespaces between the words.By using replace method and trim method
Having the same issue, works in VS Code as well - did you ever determine the issue?
lilsoymilk: that's because in VS Code, you didn't test it with the same input. It won't work there either if you use the input of the second sample test.
This comment has been hidden.
Use
console.log(str);
before your loop and you'll realize why.I'm getting the error using Javascript, "Still an empty string: expected '#' to equal false". but all my tests are displaying correctly. Anyone else come across this problem?
Your code is returning
"#"
instead offalse
. Not a kata issue.me too tho, don't why is it dispaying that way
I am still getting the error "Still an empty string: expected '#' to equal false", but all my test is working fine.
When comparing strings, you must check the output because simply str="" will not work.
my VS Code for '#' input returns false, but here I get the error "Still an empty string: expected '#' to equal false". Other tests were passed so far, what can cause this?
Your code is returning "#" instead of false. '#' isn't the input.
This comment has been hidden.
Right
This comment has been hidden.
interesting..
This comment has been hidden.
It seems like there's something wrong with the test expecting the output "#Codewars". The solution I wrote in JavaScript gives the correct output when I test it in VS Code but that test fails here.
Ya, seems right
Me too