8 kyu
Return Negative
142,351 of 373,914Deantwo
Loading description...
Fundamentals
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.
Every time I do simple kata a learn new think from std.math. Thanks ;)
This comment has been hidden.
The hidden tests contain plenty of those. The sample test case intentionally only contains that one
Assert.That(Kata.MakeNegative(42), Is.EqualTo(-42))
test as my attempt to teach people to write their own test cases.What???????? My dad are a programmer
why they return the answer wrong?????
Can you please explain in more detail what you're asking?
Because your code is wrong. Read the description of the Kata again.
This comment has been hidden.
Your solution is not exactly correct. See this article for related info: https://docs.codewars.com/training/training-example#writing-a-solution
You need to actually return the result, not print it.
Hello how to do this is question
You mean how this website works? How to do a kata in general?
Or do you mean this kata specifically?
What is your question?
This comment has been hidden.
please, do not post solutions in the Discourse. you spoil the kata for other users by doing so.
Look at the Solutions section if you want to compare your solution to others.
Верните, в таком случае просто ноль.
This comment has been hidden.
Please don't post solutions in Discourse.
This comment has been hidden.
You can see other solutions in Solutions section and learn from them.
There's a minor improvement to be made to your test suite. Currently, it only evaluates the function with a single input value (42). It's advisable to include multiple test cases covering a broader spectrum of scenarios. This ensures thorough testing and verifies that the function behaves correctly across various input types, including positive, negative, and zero values.
The Sample Test Case is one you are supposed to write yourself. And it is not like this kata is all that hard, so it feels like overkill to add all those.
The basic idea I had when I made it this kata, was to have users learn that they can't trust the Sample Test Case to be complete and they should expand it themselves if they think they need it.
If you really want to test your solution, you would submit it anyway, which has all the hidden test cases.
If you are talking about an actual hidden test case that isn't doing enough tests, then you will have to specify which programming language you are talking about.
An easy one! passed
This comment has been hidden.
You don't have to post your answer as a comment. Just do the kata again and it will be added to the Solutions section automatically.
This comment has been hidden.
You need to remove the
pass
, as your function ends there. It's just supposed to be a placeholder for your code.OP solved it, closing
This comment has been hidden.
Yup. It is part of why I made this Kata, the solution was so elegant.
Site is busted, wouldn't accept my solution but the tests all passed :(
Your code is wrong, the tests are fine:
Read the description again.
Thanks, I missed something silly!
works for me - make sure your solution return, but not print().
Was this supposed to be in reply to someone else comment?
This comment has been hidden.
Your code makes any number positive, not negative.
Hello, I don't understand what to do...
Hi! If the input number is positive, you just need to 'convert' that number to the same, negative number. For example, if the input number is 5, you must return -5, if the input number is 22, then you must return -22.
Hi ! Thank a lot ! Now it's good for me.
My code works completely on any tests both here and in VSC, but the system writes an error "expected 9 to equal -9"!
Your code is wrong, read this again:
This comment has been hidden.
same with me
I keep getting the error "undefined should equal -9" is this something i am doing wrong ? When I click test it says everything is complete but when I click attempt it doesnt work
No, if that happens, your code should return the input as it is.
Both those lines are the same.
The argument passed could also be a negative integer, at which point nothing else needs to be done to it.
This comment has been hidden.
same
main.cpp:9:5: error: conflicting types for 'main' int main(int, const char *[]) { ^ What's wrong?
Not a kata issue. Just use the initial code:
And write your code inside that function, don't create a
main
one.NASM fork with more informative tests logs.
Approved.
NASM
Is there some question I cannot see?
This comment has been hidden.
Please use appropriate markdown formatting when posting code. See https://docs.codewars.com/training/troubleshooting/#post-discourse.
^
is not the operator you think it is. See https://en.cppreference.com/w/c/language/operator_arithmetic.You should look up what
^
means in the programming language as was pointed out.If you want to do "power of", then in C# is it
Math.Pow(n)
. Not completely sure which programming language you are using though. Always best if you mention the programming language you are using when asking for help.Marking as resolved.
This comment has been hidden.
This comment has been hidden.
I am not exactly sure how this can be "again" a problem, because if you were able to figure it out once, then I wold hope it should be possible to know what to do in other kata?
Anyway, please see if this article helps: https://docs.codewars.com/training/training-example
Read this too: https://docs.codewars.com/training/troubleshooting#expected-the-same
with again im refering not to exactly this code but to it being the second time today, that i couldn't figure out by myself why the function does not get accepted. thanks for the links anyways.
Your code doesn't return anything.
CommonLisp translation.
Approved.
Clojure translation.
Approved the fork to resolve MC
CoffeeScript fork
Adds random tests.
Approved, thanks! Keep em' coming ^^
It didn't have random tests? Huh, I didn't know that.
Really wish I had checked more of the translation additions back in the day.
You're fine, basically all old TS/CS/Ruby translations are like that.
This comment has been hidden.
You do not need to post your solution as a comment. All solutions can be seen in the Solutions tab, and people can comment on the solutions there too.
im a literal genius
ok and?
you wouldnt understand
This comment has been hidden.
Your function returns a positive number when the input is already negative.
thank you <3
-1 * -1 == 1
So my kata works on my local machine, in a Jupyter notebook. But here, I get errors because I didn't do it the same as the solution and I'm not importing something that the solution has. Also my first kata wouldn't work because I asked for input, which apparently isn't available. So how do you get around this without just copying their solution?
See the initial code:
Replace
pass
with your code inside the function. And use the function's argument to get the input value. It is a number, not a list.Read this first: https://docs.codewars.com/training/training-example
the solution set-up provides you with a declaration with the name
make_negative
, so that's the function you need to writethe input is an argument passed into the function by the parameter named
number
you can print the input as shown to know what you're working with
return the result from the function to be checked by the testing code
El kata muy bien.
Hay no problemas en mi código!
:)
This comment has been hidden.
Please read this: https://docs.codewars.com/training/troubleshooting/#post-discourse
And this:
Your function returns a positive number when the input is already negative. The function's name doesn't match either, see the initial code:
Language Translation to Portuguese-Brazil:
Descrição
Neste simples projeto, dado um número, você deve fazẽ-lo ficar negativo. Mas talvez este número já seja negativo?
Exemplos
make_negative(1); # retorna -1 make_negative(-5); # retorna -5 make_negative(0); # retorna 0
Notas
O número pode já ser negativo, tal qual nenhuma mudança é necessária. Zero (0) não é verificado para nenhum sinal específico. Zeros negativos não possuem sentido matemático.
Stop posting these kind of info as suggestions! Users can translate using their own tools or just learn English :)
I am confused as to how to start many of these. I haven't done enough of them to get the pattern. I am a little autistic so sometimes the words don't make sense. I understand what to check for but what am I checking? DO I need to specify an input toget the numbers? IF I don't understand that I cannot deal with the rest of the logic.
It all depends on your chosen programming language.
Ususally you are programming a simple method in these katas. So you need to program it to take an input and return an output.
thanks. I am doing python. I can put an input in the function. that was kind of what I was thinking, but that kind of shit drives me crazy. Just tell me where to get the numbers form and I would be fine. It happens a lot. I need to do like a hundred before I will understand the way they ask the questions.
See https://docs.codewars.com/training/training-example#writing-a-solution
@craigM222, almost every single kata on this site will provide the input within the function declaration, in this case, the input is the parameter
number
also, a helpful step in coding is to print the input like this:
craig im fr like you
It took me a little while to realize that I was checking if the number was a negative instead of positive lol.
This comment has been hidden.
This comment has been hidden.
Please use the spoiler flag and appropriate formatting when posting code. See https://docs.codewars.com/training/troubleshooting/#post-discourse
Answering your question: the top one always returns
num
unchanged.I don't know which programming language that is. But it looks like the first code sample is returning
num
without changing it.I am not sure what
cout <<
does in this code though, but it at least isn't changingnum
.it's C++ which uses
cout
for printing to consoleThis comment has been hidden.
Good for you. You can compare your solution to other submitted solutions in the Solutions section. No real need to talk about your solution here.
This comment has been hidden.
difficult kata, but eventually i got the hang of it after a few hours
This comment has been hidden.
Please don't post solutions in the discussion section. If you want to submit another solution, simply do the kata challenge again.
This comment has been hidden.
It is a weird solution, but it works. So why is this an issue?
Marking resolved.
Also, please don't just post valid solutions in the discussion section.
my test passed the first time and the submission was wrong so i added the if condition
I don't know which programming language you are talking about. But no, looking at the 230'599 completions, I highly doubt the "submission was wrong".
Read the kata's description again. And yes, the basic test case is intentionally lacking. You need to learn to write your own test cases for the "Test" function.
I am using Ruby. however when i said my submission was wrong, i meant the code didnt pass the test.
Ah ok. Guess I just didn't understand what you meant then. And I am not sure I understand why you posted at all.
bu biroz qiyinroq
Only if you don't read the description.
This comment has been hidden.
What if you pass your code a negative number?
Try editing the "Example Test Case" to pass a negative number and see what happens. Does it still pass when you press the "Test" button?
It might help if you show the output if the test that is failing.
Ye, 2 minutes after I asked I tried negative numbers and saw the problem hahah. I added some logic to check if it's already negative and now attempt is passed too
This comment has been hidden.
A negative zero doesn't make mathematical sense. Normally zero has no sign whatsoever. It is neither negative nor positive. That is why most programming languages also don't have negative zeros.
There are however a few programming languages that do have negative zeros in some cases. But they are more the exception.
I am sure google can tell you more about it.
The kata description also says this:
This comment has been hidden.
Because of this:
Yes, basically you didn't read the kata description correctly, or misunderstood some math.
For example, what would your code return if you supplied it with a negative number? What did the kata description say you had to do?
This comment has been hidden.
Hi, welcome to Codewars!
Your code is printing instead of returning. This page breaks down the Codewars trainer and what it expects from you.
Also, consider joining the Codewars discord server. There are dedicated channels where you can get help there (e.g.:
#help-solve
).As mentioned, you need to return the result, not print it.
Like
return number
for example.This comment has been hidden.
Use the initial code and return the result instead of printing it.
Your code seems to work on an array instead of single integer inputs. And yes, you need to actually
return
the result, notprint
it.This comment has been hidden.
Which programming languge are you using?
Explaining what how the tests are failing would likely help too.
I would assume it is an issue with your code. Ensure you have understood the kata, so check its description.
I'm using Ruby! The tests say that they are expecting -9 but instead getting nil. Not sure if I'm able to display my code? I ended up just using an if/else statement that passed the attempt, but I would've ideally liked to use the ternary
Sounds like you weren't returning anything.
Remember when using ternary operator, you need have the
return
at the start of the line. Like this:This comment has been hidden.
-x in google search means filtering x out in search result
This comment has been hidden.
This comment has been hidden.
The test is passed, but when I hit attemp now the test doesn't work. In both test and attemp have the same sample.
Which programming language are you using?
Test and Attempt aren't the same, Test is the "Sample Tests" that you can write or edit yourself, while the Attempt is the hidden and more strict tests.
If I was to guess, you have misunderstood the goal of this Kata, so I suggest you read the Kata Description again.
I'm using JS.
The test says, 9 expected to equal -9. But I passed the test.
I tried with attempt which also says 9 expected to equal -9. But it doesn't passed. Even though my result is -9.
"9 expected to equal -9" means that you returned
9
but the test expected you to return-9
. (Or vice versa.)You can show your code maybe.
But that is the problem, my result is returning -9.
No, it's not. That's why it doesn't pass the test.
Your code passes the single sample test because the input value is a positive number.
Check that. What's your code doing if the number is already negative?
It is returning the number as it is passed in the function.
Btw, it is returning the -9. I did the console.log().
Now your code is different of the one I saw. Still, your code is wrong, read about that math method you used there. The if condition is wrong, the else is never reached.
This is the test you should use:
console.log(makeNegative(-9))
and you'll see your code returns 9, not -9.All right. Thank you so much. Now it passed the attempt.
But I still suggest that the ones who created this KATA to check it.
Sorry, but check what? The tests are fine.
There is nothing to "check", your code was simply wrong.
Good
I got the same with both this exercise and the previous one I tried
If you have the same issue, then the same advice as given above should help you.
Your code is wrong in one way or another. As a minimum you need to tell us what programming language you are using and what the error is from the tests.
This comment has been hidden.
Please mark your post as having spoiler content next time.
Your code returns a positive number instead.
This comment has been hidden.
I does this exercise in visual and after that pass here but doesnt work, why?
Hi @TomasVainstub and welcome to Codewars!
I am looking at your current solution, and it seems you have renamed the function to
pasajeNumeroNegativo()
, but the original Codewars kata is expecting you to write a function calledmake_negative()
.See below for the original setup for the function:
So rename your function to the correct one Codewars is expecting, otherwise it will not work.
When I solved this kata in python, one of the tests was incorrect. It expected -9 as a result for the input -9, when the result should have been 9 instead
Hi @nereno96 and welcome to Codewars! The Python error messages can be a bit confusing at first: they are in the format:
Expected
what_you_returned
to equalthe_correct_kata_answer
So maybe you saw something like: Expected
-9
to equal9
?In that case, your code was returning
-9
and the correct answer was9
. You should read this Troubleshooting page it will be maybe useful for your Codewars journey (specifically the section about "Printing your input"). Cheers,You should return a negative number, so if the input was -9, you should return that, not 9.
when I tried to run the code outside codewarriors.com it worked, but it won't in codewarriors. What should I do?
it already worked
This comment has been hidden.
Warm up
That was easy!
This comment has been hidden.
There is no need for hints like this.
Since this section is shared between all programming languages and you didn't even mention which one your hint is for, your hint is kinda useless. Also no one really goes looking in the comments here for hints.
If people need help, they would likely get more help from google or asking on the Codewars Discord server.
This comment has been hidden.
Your code returns a positive number instead.
omg xD thansk
This comment has been hidden.
Read this: https://docs.codewars.com/training/troubleshooting/#post-discourse
Your if condition is wrong.
Lets Fun!!
This comment has been hidden.
First of all, which programming language are you using?
Second, what is the output from the failed tests?
This looks like a common mistake. You have misunderstood the goal of this kata, or a math error, I suggest reading the description again to make sure you understand the goal.
The "Test" button only runs the single test in the Test Cases section you can edit. You can extent it with more tests yourself.
The "Attempt" button runs the hidden test cases that you have to solve.
Basically. What does your code do if the input is already negative? What are you supposed to return if the input is negative?
This comment has been hidden.
Because that isn't the goal of this kata? Or what is it you are trying to ask? Is that your whole code?
It helps a lot if you explain what is wrong. Are the tests failing? Which tests? What is the exact test output?
I marked your comment as a spoiler, since it contained some minor amount of code that I guess could be a spoiler. Please mark your comments as spoilers in the future.
have you tried reading the error message?
OP solved it ,closing
D translation
Accepted.
Factor translation
Does not work well for me,alse chked in idle works fine
You need to
return
the result, notprint
itWhich programming language are you using?
What isn't working? What error message or error output are you getting?
The kata has been completed by over 150'000 users, so I really doubt there is an issue. It is most likely an issue in your code, so if you show what you got we can try to help you.
Yes, i did work with return Sorry, my bad, maybe i missed instructions
It's the same in all katas. What you print will be shown as logs, but the tests only control what your function returns.
This comment has been hidden.
Please mark your post as having spoiler content next time. Read this: https://docs.codewars.com/training/troubleshooting
Your function is returning 9, that's a positive number instead of -9.
This comment has been hidden.
Not a kata suggestion, please don't post solutions in Discourse, use Solutions section to discuss them.
This comment has been hidden.
This comment has been hidden.
Your code is incorrect. This is not a kata issue. Please read carefully the description, the message returned by the test is sufficiently explicit.
@akar-0 is there a way the default test case output can be changed?
People clearly get confused when they see
"expected 9 to equal -9"
, reading it as if the test expected it to be9
. I forget what programming language that is, but it really just annoys me every time I see someone not read it as"expected (9 to equal -9)"
.I'm still learning how to use fully Python's framework but you may try something like this: https://www.codewars.com/kumite/627651c44ecc2c505a2e964f?sel=627651c44ecc2c505a2e964f
That wasn't Python, that was javascript. Python's default error message is like this
actual should equal expected
, but the idea about how to handle it is the same.You're right, my bad. Though I'm not better with JS framework :)
the test cases were wrong
I don't think so. Which language, which test?
You need to be more specific. The kata has been solved 144'000 times across multiple programming languages, so I highly doubt the test cases are wrong.
I suggest you read the kata's description again. If you still think there is an issue, tell us which programming language you are using and copy-paste the output from the failed test.
This comment has been hidden.
What do you mean? There is no issue with the kata that I am aware of, and you didn't specify where or which programming language you saw it on.
I suggest you read the kata's description again.
This comment has been hidden.
The output "expected 9 to equal -9" means that your code returned
9
and the test case is comparing it to the expected result which is-9
, since they are not the same it fails. The input in that test is-9
, so it does not need to be negated.For a simple math lesson, see:
Thanks for the reply!
"expected 9 to equal -9" but my function returns -9?? not really sure what I'm doing wrong here
Nevermind my fault did not read the description properly
Without your code, we also don't know.
Got it now, I did not read the description properly
What was the problem? I'm getting the same and Idk what is it
Your code is returning
9
, it need to return-9
.Read the Kata's description again.
This comment has been hidden.
Please don't post solutions in the Discourse section. If you want to share another solution, you instead simply do the kata again and it will be added to the Solution section.
I have marked your post as spoiler.
This comment has been hidden.
Don't post solutions in the Discourse section.
If you want to just show off a new solution, simply do the kata again and it will be added to the Solutions tab.
This comment has been hidden.
Don't post solutions in discourse page. Thanks.
If you want to just show off a new solution, simply do the kata again and it will be added to the Solutions tab.
This comment has been hidden.
You must return the result, not print it.
See: https://docs.codewars.com/training/troubleshooting#expected-the-same
Esspecially the last bullet point.
COBOL translation updated to new test suite.
Commented with feedback. Waiting for requested changes.
I think we can avoid situations like this in the future, if all changes to a translation are done with forks on the latest version of a translation.
First time I see changes suggested as a fork on a translation, and it seems like a lot of work to maintain that way. I edited test cases for all languages to be identical a while back, doing that on each and every fork would have taken more than double the time. Is there no way to make a new fork off the Main? Instead of making a new fork of the old translation? It seems rather silly if you can't.
Unfortuantely it;s not possible to fork current state of a kata, but it's planned to be added.
It is somewhat possible to recreate a current state of the kata:
Remaining snippets (preloaded and author's solution) are harder to get, but they usually are empty or do not change.
The biggest problem is to find out that a fork is outdated. Interleaving forks with direct edits causes problems here as it's easy to miss or overwrite edits. Sticking to one way of working with kata, be it forks or direct edits, mostly prevents this, but considering the fact that not many users have access to edit panel, not everyone can use it. That's why introducing changes with forks can be considered recommended, but I can see how it can be tedious.
I can't wait when we finally get the possibility to create a fork from current version of a kata.
Approved by author.
Hi! im new at codewars, figuring out how to use it and learning to program. This is the first excercise im doing here and i don't understand why if i put "test" and everything turns to be ok, when i select "atempt" it says i failed. I may have failed as im new at this, but i would like to understand whats the difference between one and the other.
Read this: https://docs.codewars.com/training/troubleshooting/#test-attempt
When you press the "Test" button, you are running the Sample Tests, which by default in this Kata only checks if you return a negative number when the input is positive. If you read the Kata description again, you might notice that if the number is already negative you still need to return a negative number.
I prefer to have the initial Sample Tests be simple, so you can learn to write your own Sample Tests. I don't know which programming language you are using, but the Sample Tests should be easy to edit.
When you press the "Attempt" button you will instead run the secret tests. They are designed to validate your code with edge-case tests and some random tests so you can't cheat your way through it by guessing the tests.
The output of the failed tests should also show you what your code returned verse what you were supposed to return. The names of the tests that failed might also be a hint as to what might have failed.
i see that for some of the codes using abs, some use include cmath and some do not, so when do you need to use cmath?
I don't know which programming language you are asking about.
This Discorse section is only for discussion about this kata itself, if you want help for the specific programming language or programming in general I suggest asking a better place. You could check out the Codewars Discord server for example.
COBOL translation available for review!
Done.
make usre you return num;}
What is it you are trying to suggest? Is there something that doesn't work like it should? Or are you just being silly?
If it is an issue, you need to say which programming language it is about and more details about what the issue is.
kata hint != kata suggestion
Perl translation kumited
Approved.
You cannot use x for some reason, I had to create a new int y and return that, can anyone explain why using x is an issue?
No idea what do you mean with that, check Solutions page, using x is possible.
You haven't mentioned what programming language you are using, and you gave no code example, so it is really hard to answer your question.
This comment has been hidden.
Please remember to mark your post as having spoiler content next time. Your problem is related to x being declared with final keyword, you can't modify its value like that. You can simply return the value you were assigning to it, or remove final keyword.
This comment has been hidden.
For formatting information, see: https://docs.codewars.com/references/markdown
This comment has been hidden.
Please use spoiler flag next time. You don't have to call the function inside your code, the tests do it for you.
I am sorry, my first comment. Will be more careful!
Did you read the Kata description? Did you read which tests failed and why? The failed tests will show what the test received from your code and what it expected to receive.
Your code works when the input is
9
. What if the input is-9
? Do you know what the output should be in that case? See the Kata description if you don't know the answer.Done!
@hobovsky, why are you trying to change the code examples in the description? You keep changing it to:
That is not better than the current, and I see no reason to change it to that.
I did this because I was trying to update Scala tests of the kata to Scala 3 and I noticed that description is missing Scala code block. As I believe that language blocks cause more problems than they are worth, in general they are nothing but problematic and they are main source of kata maintenance problems, and I prefer language-independent descriptions, I simply removed all code blocks and repalced them with language-neutral examples.
Forgive me messing up the description. If you prefer having language blocks then OK, but remember to add example for Scala (it has never been there). And have fun resolving merge conflicts on incoming translations ;)
I checked all the available languages for the Kata before reverting it, and they all had a code block in the description. I have maintained this Kata for 7 years, never had an issue with it.
It does look like the Scala language is just using the
C
code box, which is a little odd, but at least it is there.When you select Scala you see example for C because there's no example for Scala so Codewars displays the first block from all language blocks, which is C, and which is not correct for Scala.
I added a code block for Scala. I assume it is correct at least.
@hobovsky, I found a fun solution. I added your "text" code box as the top one, so it will now show as the default if there isn't a language specific one.
Oh, this is an interesting idea indeed.
I think another useful thing would be to have long sets of examples sorted by language tag: this way translators more or less know where to locate the example for a specific language without a need of scrolling back and forth.
This comment has been hidden.
You are misusing the Conditional (ternary) operator (see examples following the link).
Yeah, as akar-0 says, you are using conditional (ternary) operator wrong.
When using conditional (ternary) operator you need to make it as small as possible and not too complicated. It is a shortcut to a normal
if
starment, not a replacement.Basically you cannot call
return
inside the conditional (ternary) operator, and that is all your issue is. Istead try these:With conditional (ternary) operator you normally replace the value in a call, not the call itself.
This comment has been hidden.
This comment has been hidden.
Your problem is right in the description:
But maybe the number is already negative?
number == (-number)
will always returnfalse
.Except with 0.
Oh yeah, you are right about that. ^^; It will return
false
for anything but0
.This comment has been hidden.
This comment has been hidden.
Marked as resolved, since this is not a suggestion for the kata at all.
Very fun exercise!
This comment has been hidden.
Which programming language is this? It is much easier if you mention which programming language it is.
Does the error message not say where the syntex error is? Showing the error message might help a lot.
Are you sure you have all the
using
s/import
s you need?I don't see you calling
return
anywhere.The FAQ might also help, and it has some information on how best to ask for help too.
This comment has been hidden.
sorry. Its JavaScript
I don't get a syntex error when I use your code. It just tells me the function doesn't return anything. Which is what I already said.
You should read about how
return
works.This comment has been hidden.
When your code is run on the sample test, you get this useful error message:
which means the test suite expected your answer, (which is
undefined
), to equal the value of a negative integer, (which is-42
). So, this shows that your code does not return a value.also, please use a spoiler tag when posting code (I have added the tag)
Then you have forgotten to put
return
in front of that ternary operator, there must be areturn
or else nothing is returned. If your code has noreturn
, so it returnsundefined
. Example:PS: JavaScript's way of not defining a return type is confusing. Why do you think it would be a good idea to return a text string if the input is not a valid number?
This comment has been hidden.
Hi again, read this, please: https://docs.codewars.com/getting-started/solving-kata
There is no need to post solutions in Discourse, you can discuss about your solution in Solutions after you submit your own. You can also see there other solutions and check if there are other ways to solve the kata (there almost always are).
Thank you for giving this kinda information .I appriciate
This comment has been hidden.
My first attempt on R translation. Please review and approve ~~
Aprroved.
This comment has been hidden.
Not a kata suggestion, and that doesn't work.
Please don't post solutions in the Discourse section. That is what the Solutions section is for. If you want to submit another solution, you simply click "Train Again" and submit your new solution, it will then be added to the Solutions section.
sorry about that, how do i delete the comment?
You can't once it has a reply, don't worry about this one.
You can't. Hence the annoyance when people keep doing it.
I had no idea about that since this was my first comment, sorry again!
This comment has been hidden.
Because you misunderstood the challenge. Read the description again.
if the num value is negative, then the answer is totally wrong
This comment has been hidden.
Marked your comment as spoiler. You shouldn't post solutions in the discussion section. If you want to show off a new way of solving the kata, you simply have to "train again", and it will add your new submission to the solutions section.
See the the FAQ for more information about the discussion section.
PS: There is an easier way to solve this kata than that.
This comment has been hidden.
Not sure which programming language that is. But it looks like you misunderstood the challenge.
The "Test" button runs the test-cases that you can edit yourself. You should make your own test-cases, as the initial test-case is very basic with just
makeNegative(42);
.If you read the Kata desctriction again, you might understand what the issue is. But what do you think your code would return if you run
makeNegative(-42);
? What should it return according to the Kata desctriction?Marked as resolved, as this is an issue with your code and not the kata itself. Please see the FAQ for details.
In javascript it's
makeNegative
, notmakeNegitive
C version generates warnings.
No it doesn't. The reference solution no longer generate STDERR warrnings.
Read the other identically badly written issue you made below. Or make a new issue with actual information in it.
C-version should have random tests. Docs: https://docs.codewars.com/authoring/guidelines/submission-tests
This comment has been hidden.
This comment has been hidden.
I don't see why that would matter. I like that the random tests can be called "should_handle_random_positive_test" and "should_handle_random_negative_test", but I am not attacted to it if that is what you worry about.
But feel free to write a new random test if you want, then I will update the kata with it.
This comment has been hidden.
C version generates warnings.
Again. More information would be nice.
This comment has been hidden.
This comment has been hidden.
It doesn't matter what causes the warning to show up, problematic final solutions must be fixed too, and if the author doesn't do so, I'll reraise the issue.
Do you just like raising issues?..
This comment has been hidden.
This comment has been hidden.
@FArekkusu: could you please post the link to the list of kata to fix when you raise those issues, so that people can track the info and have an idea about what's the actual warning(s)?,
https://github.com/codewars/content-issues/wiki/List-of-C-Kata-to-Update
This way, we could avoid a lot of useless noise/tensions. Thx.
@Deantwo: As of now some of the common header files are already pre-included in compilation process, but that's not an expected and standard behaviour, hence it is not something which should be relied on as that might change in the future, breaking the whole translation.
This comment has been hidden.
To anyone interested, here's a word of explanation:
abs
and family is declared instdlib.h
. It needs to be included in every snippet which usesabs
This comment has been hidden.
Julia should use
camel_case
/camelcase
I don't know anything about Julia.
Would changing it break backward compatibility? Or do you just mean the method's name?
I meant the function name, not sure if backward compatibility works in Julia, if I knew hw to do it, I can fix the problem myself ~~
Yes, changing the method/function name would make all the currently submitted solutions wrong. But if it is a real issue, you should probably just do it ASAP. So fix it if you want, just be sure to change it everywhere for the Julia version of the kata.
I don't know if I would class this as a major issue though. Since it doesn't look like you even know which format is officially most correct.
https://docs.julialang.org/en/v1/manual/style-guide/#Use-naming-conventions-consistent-with-Julia-base/
According to this style guide, the function name should probably be
makenegative
.Not a super pretty style to use I must say.
Yeaa directly changing the function name would invalid all solutions but backward compatibility might not just like in python / ruby. It's not a big issue, but just not good practice, and wrong naming convension can get you to jail in real industry (~~ XDD) Unfortunately, I haven't found out the method to do so, so might as well leave this issue open until it's fixed.
BTW, thanks for the link, and
snake_case
is also preferred by adding_
between words.I updated the Julia version of the kata to use the function name
makenegative
instead ofmakeNegative
, as discussed.A few users might get an error about missing functions, if they started the kata before the change. If that is the case, simeply click the "RESET" button to reset the kata to the new version and try again,
Converted language-specific blocks into language-agnostic description
What?! Why?!
And you wrote it wrong!
To prevent future merge conflict issues :)
Where's the mistake?
You can always go to
revision
section and copy previous stuff and change it back :)it's make negative, not invert sign ;-)
fixed (sorry for the inconvenience caused)
@author: you reverted back, that's ok, but please realise this makes the translation process a hell :)
Ok. Reverted.
Feel free to post a suggestion next time instead.
I am sure we can figure out better ways to fix that issue. Such as have people not edit the description or something.
Thing is, the description has to be changed for any new language as long as there are language specific code blocks in it. That's why they are suggesting to do that change. What about just:
?
Yes, but I (or someone else?) can just edit the description after the translation is accepted.
But it is not like there are many many translations, so this doesn't seem like a big enough issue to totally destory the description for.
This comment has been hidden.
What you do in the first line, doesn't change that variable's value. The 50 tests your code passes, are the tests where the input is already a negative number. Please mark your post as having spoiler content next time.
You didn't read the kata description correctly. You did not solve the kata, that is why you failed half of the tests.
See also the FAQ for some hints and better ways of asking for help.
This comment has been hidden.
@Codynw42 this is the last time you addressed anyone in this (or similar) manner. There will be no second warning.
Crystal translation kumited:)
Accepted.
This comment has been hidden.
That's a question.
What is the error message? Which language? What's the input? What's the expected output?
This comment has been hidden.
Sorry, iam new here, maybe there is a way to do the questions iam not familiar with, can you check with C# and see if you are having the same problem im having, thanks for your time.
Ooooh sorry, so you use test window to test what you created at the top, sorry it was running the default one, there is no issue here, thanks for your time.
Just looks like your
if
statement's logic is backwards.This comment has been hidden.
There are many ways to do this kata, but yes that is the easiest way yo do it. You can check the inspiration I had for this kata if you want to see a negatively creative way to do this. Here: https://www.codewars.com/kata/55685cd7ad70877c23000102/discuss#5568630f8095a17c6000008f
Why It does'nt accept scanf and printf?
Your functions in Codewars must return a value, not print it. Read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
Forked python translation with new test framework used and 3.8 enabled
Accepted.
My solution is very basic and easy for py3 I hope it's helpful.
Isn't really the purpose of the discussion section or the website, but thanks for doing the kata.
You can view all solutions on the Solutions tab, vote for your favorites and even comment on them.
Ok Thx! I am new here, So sorry about that :)
This comment has been hidden.
Why are you rounding it at all? The description say nothing about rounding.
Thanks! My mistake misreading regarding how to treat 0s :)
Your solution would fail this:
The starting function name is makeNumberNegative(), however the test requires makeNumber() ...
In which programming language? I can't find any mention of "makeNu*" in revisions at all.
It was in JavaScript
That's the starting code in javascript. Click reset.
Yeah I think I messed something up copy/pasting from my editor... My bad, apologies!
that's why I keep getting one pass one fail one pass one fail!!!
What areou talking about Dawintch?
This comment has been hidden.
Not a kata issue, your solution is wrong. It does not conform to followign requirement:
Also please see this FAQ for how to best debug your solution and ask for help. Namely it would be nice if you put your code in a code block, and mentioned which programming language you are using.
This comment has been hidden.
You are returning string, but you are supposed to return number.
f"{x}"
gives you a string.This comment has been hidden.
In your else your code returns a string instead of a number. Read this too.
Thanks, Chrono79!
I'm really confused ! Anytime I test the code it runs but when I attempt, all of them are errors, even the one of the Test. Can anyone help me please?
Please read through this FAQ and come back with questions if still having any.
Thanks for the link ! I read the point that I was concerned by and it seems like in fact my code is not passing the test. I'll give it a try again and if it still doesn't work I'll skip or search by another way.
Thaaaannnnks !! It finally worked !
im getting the same
@Codynw42, and what is your issue? What is the error message? What is your code? Can't help you without some information.
Check the latest post above, you can see the code there.
This comment has been hidden.
Because your code should return the result, not print it.
this should be a 1 kyu kata :^)
the larger kyu numbers are the easiest.
that is the joke. (see the ":^)")
It's how the ranking system works. kyus are like negative numbers, when you ++ them, they go lower, as the number.
... I'm mocking the easiness of the kata in a comment that ends with ':^)' which is there to indicate -a very obvious- sarcasm. I obviously have used this site and know how kyu works.
see also: https://en.wikipedia.org/wiki/Emoticon#Creation_of_:-)_and_:-(
Why did I even need to explain this? Why did anyone even pay attention to this easily dismissible comment?
Don't worry, your commment cracked me up. Never give up the hope that sarcasm can bring <3
Hello!
Maybe a good test case to add would be a value that is NaN. Requiring solutions to ignore anything that is NaN and simply return that value passed.
Nobody's going to change the requirements anymore.
Thanks! Just figured I'd throw it out there.
The input is a number, so it can't be a string.
This might work in some programming languages, but not all. And I do not want to make this kata overly complicated by have specific instructions for each programming language. This kata is meant to be simple and easy for all.
yo
This comment has been hidden.
Not a Kata issue.
my first Kata and I´m proud that I can solve it.
Racket translation
Great exercise for a simple "If Statement" practice. Thanks!
That is one way of solving it yeah. I prefer the mathematical solution.
I'm afraid that tests are broken for Java and Go, assertions are wrong as they expect incorrect results in some cases...
No, you're wrong, both are ok. Maybe you didn't understand what to do, read the instructions again. Also, when reporting a problem, be as descriptive as you can, for instance in this case, show the input, the expected value and the value you think it should expect.
Everything Chrono79 said.
Without examples of what you are talking about it is impossible to identify any issues and not suspect user-error.
Read the kata description again and then try to solve it again. A thousand other warriors have had no issue.
You are right, I didn't read it properly, I thought it was just a matter of changing the sign of the given number...
You are not the first or last to make that mistake. So don't worry about it. Do however learn from it.
Dart translation
Bump.
Bump you too. I'll look at it when I have time. This website is horrible on my smartphone.
A PHP translation has been waiting for a while, anyone want to approve it?
Don't know why I don't get e-mail notifications about those.
I commented on it.
I have accepted it and fixed whatever issues it had manually.
This comment has been hidden.
puts
? Shouldn't you be doingreturn
?how do i do this? I couldn't do it by myself and so I looked on google on how to turn a postive number into a negative number but i still don't understand where to put the code or if i have to modify the code to suit my program.
You have to write the method so it return the negative number. Basic programming.
If you tell which programming language you are using, we might be able to help you more.
I am using java, i know what a method is
This comment has been hidden.
Read the description again, you seem to have misunderstood the challenge.
Not a real question about the kata, so marking resolved.
"don't overcomplicate the things"?
consider that some input numbers might be already negative
Still didn't get it. Maybe I just don't understand english, but I just can't figure it out. The tests that fail are the ones that aren't negative yet.
Nevermind, got it.
This comment has been hidden.
This comment has been hidden.
Thanks for the feedback, makes sense now its been shown
This comment has been hidden.
Why are you telling us in a comment though? ^^; You can easily see all posted solutions once you have completed the Kata once.
This comment has been hidden.
Your code returns a positive number instead.
Yeah, I figured that out after some trial and error
Scala translation available for review.
Ok, gave feedback. But why does it already seem to be approved?...
Somebody else approved it I guess
This comment has been hidden.
Not sure what programming language that is, but what you are doing looks way more complicated than it has to be. There are many ways to solve the kata though.
This comment has been hidden.
Ok.
Make it generic machine independent code. Good work.
Good easy to understand Kata.
This comment has been hidden.
Your function should return, not print. Not a kata issue. And mark your posts as having spoiler content when they do.
This comment has been hidden.
Yes, that one, but your code was visible in the homepage, so it didn't apply (dunno why). For plain posts like this one, there is no need to use it (there is no spoiler in it).
okay, good to know thanks will do from here on out
I cannot locate where to put my code. What is up with this kata.
Found it. I had to click Train again. Why I do not know.
Hi, I made a NASM translation for this Kata.
Don't see how that is a suggestion.
seriously? You never approved a translation before??? It IS a suggestion to you, to approve this translation so that NASM is available for your kata.
I guess you have never owned a Kata then. The
Issue
,Suggestion
andQuestion
comment types are for Kata feedback. I can mark it as resolved when I feel the feedback is answered.A translation is showed elsewhere, I get a nice little blinking icon and a private place to review and discuss the translation.
I don't see why a comment on the Kata is even nessarary, and even less marking it a
Suggestion
.The Kata is a few years old now, I have accepted plenty of translations. Some good, some bad, and even some broken.
So what is your point again?
My point is that, doing so, you're not showing the "correct (polite!) way" to other users. Those who read the discourse didn't have any "nice little blinking icon", so the only thing you're showing here is that you make a rude comment to a person who actually made "work" for you.
And for your information:
Ok sure.
This comment has been hidden.
You aren't doing the Kata correctly, you better read the description again.
This comment has been hidden.
It looks like you aren't returning your variable. Try changing it to:
ahhh, it's OK THX :D :D :D
Javascript (and potentially other languages): Faulty or missing test cases for potential
-0
, although the case is explicitly mentioned in the description (the kata is too old to change test cases, but afaik the description can still be modified).This has been mentioned here before, but imho is simply a mistake and should be an issue, not some half hearted comment that can be ignored.
Negative zero is a mathematical impossibility. The note in the description is mostly just so people wouldn't ask about it, yet here we are again.
There is already a test case for zero in Javascript, so I don't know what you are trying to say.
This is programming and not math. IEEE754 has negative zero and is almost the absolute standard for float in all languages (including javascript's number). The description explicitly states
Yet if i write a function returning
-0
for said input, there is no problem.The values are checked for equality, not being identical. Yes,
-0
and+0
are not identical, andObject.is(-0, +0)
givesfalse
as a proof, but they are still equal to the same value -0
. Stop talking nonsense.https://en.wikipedia.org/wiki/IEEE_754 We are talking about integers, not floating-points or whatever else. See also: https://en.wikipedia.org/wiki/Signed_zero
But yes as FArekkusu said,
Test.assertEquals(-0, 0);
will result in the test passing.Only place this might be an issue is for those weird programming languages that don't have integers. I only know of Haskell, but do let me know if there are more in this Kata that need decimal point tests.
Javascript does not have integers (in the sense you are talking about) - 4.3.20 Number value - primitive value corresponding to a double-precision 64-bit binary format IEEE 754-2008 value, though you can sometimes emulate them (e.g. with bitwise operators or typed arrays).
I did what had to be done, so that people will see the issue. I don't intend to waste my time with this any more.
Making a "turn negative" kata and not adding a proper remark about
-0
is asking for it.Interesting statement, may I ask you what is this issue you're talking about? JavaScript is comparing values, not some magical being behind the curtains. If JS thinks that
-0 === +0
, then maybe-0
and0
are actually the same value (wow unexpected, such impossible)? Of course, you may not agree that zero equals zero, but in this case are you sure you should be talking about it here?You know
0
and-0
are not the same number, so why are you then arguing as if they are?When I get a function, that by spec explicitly should not return
-0
for an input of0
, but returns-0
, it's a mistake. Whether you like it or not. If it wasn't specified too strictly, one would have to research what it does for these cases - but given the details as-is, I don't understand how you can even try to debate it.You seem to know
Object.is
. I expect you know1 / -0
vs1 / 0
, or what they look like when writing to a typed array and reading the related bytes. They obviously make differences in code and are not some "magical being".Edit: Reading through the comments again, i don't actually know for sure whether you are aware.
0
and-0
have different binary representations in float, which also behave differently for some operations.0
is 0000...00002 (64 digits), while-0
is 1000...00002 (64 digits) for javascript number, which as noted uses float64 IEEE754-2008. They are part of the denormals of IEEE754, but the specifics are a longer topic and don't belong here.Because they yield the same value. Even if you keep crying about how +0 and -0 are not identical, they still yield the same value even in binary representation:
Sorry, but this is unrelated here.
It actually says
"Zero can't be negative"
. Unfortunately, this is not 100% true in JS; fortunately, JS still thinks they are the same. You want to follow the spec so much? Your choice, but don't make a fuss of how "you're correct and others are wrong".Apart from you missing the
.toString(2)
on the other side:(X >>> 0).toString(2) === (0).toString(2)
, do you even realize for how many numbers that is true? Do you want to argue now that0.5
is the same value as0
? Or4294967296
is the same as0
? EvenNaN
would be the same as0
by your logic. If you mean that Int32 does not have signed zero (note here that javascript>>>
behaves as if on UInt32, which obviously doesn't have signed zero), yes, but i don't see how that relates to the topic at all.The description explicitly says (i am now repeating quotes i already made in this same thread):
If that is not explicitly saying that
makeNegative(0)
should not be-0
, i don't know what would.PS: the point is exactly that they are different in their binary representation, but i already noted that...
This comment has been hidden.
Added the extra decimal point test cases for JavaScript. Any feedback on them?
This comment has been hidden.
I don't know which languages don't use integers, since I didn't make the translations and don't know most of the programming languages. I don't have time right now to go through all of them one at a time.
Whoops, made a mistake myself. You will have slightly incostent tests across the different kata versions because not all languages support duck-typing.
Apart from that, you can forget about all this nonsense about
±0
. Technically, numbers in JS are floats, but in reality they are integers, even though they use float division instead of integer division and can't go beyond2^53 - 1
without "losing precision".You took some of the good stuff today, didn't you?
@Deantwo what i originally complained about was only that a function which returns
-0
for an input of0
passes, even though the description sais thatwhich imho clearly requires that a return of
-0
is not allowed. That would invalidate a lot of solutions though, so perhaps slightly rewording the description may be preferrable.PS: this discussion exists on the top voted javascript solution aswell.
This Kata is meant to be super easy. I am sorry that the note I originally wrote for the C# version of this Kata doesn't make sense in your fancy JavaScript world.
Do you want me to just remove the NOTE at the bottom of the description? Or add a "(not for JavaScript)" mini note? I can also make a "(
if (name == "ASDFGerte" && language == "JavaScript") { negativeZeroNote.Visible = false; }
)" if you want.But you still haven't supplied me with a code example...
This comment has been hidden.
Changed the note to "Zero (0) is not checked for any specific sign. Negative zeros make no mathematical sense."
Thanks for the feedback. XD
maybe this it too easy....
That is kinda the point and why it is tagged with fundamentals.
As I mentioned in a comment down at the very bottom of this discussion page, this Kata was based on a DailyWTF article. And I do find it a lot of fun to see how other people do it.
Needs edge case like -1 in all languages (see
lobo_tuerto
's post below). Also sample tests are missing in Ruby. I raise an issue so I (or any other power-user) can add it in a week.Added example test cases to Ruby.
Added edge test cases (1 and -1) to all test cases.
Thank you.
Ruby version doesn't have any test conditions
Added example test cases to Ruby.
This comment has been hidden.
This comment has been hidden.
Why do you say it is wrong? Looks fine to me.
@Deantwo what happens when you pass -1 to that function?
Ah, true. Well, comment on the solution then. Not much I can do about it sadly since the Test Cases are locked for me.
I also don't know much about Ruby, does it have decimal points in the
num
variable?It says that variable x might not be assigned. Please help.
Which pogramming language? What is your code? Where are you getting the error?
This comment has been hidden.
This comment has been hidden.
thanks!
Thanks for sharing this kata .
testcase 2 for java reads: assertEquals(-9, Kata.makeNegative(-9));
Yes it does. It is meant to be that way. What is the issue?
Please read the kata's description. If a real issue is present, open a new issue with more information.
I did not read it as throughly as I thought. Sorry :P
code pane is non editable I am not able to submit my solution
Not a kata specific issue, so I can't help with that. I have no issue when I try.
make the size of the viewer less and the button submit will appear
What is "Assert::That"?
In what context? What programming language? Helps if you post some code.
Marking question as resolved because no further information was given.
For JavaScript expects "-0" as a result. Which you described as n/a in the description.
A negative zero is not mathematically possible.
None of the test cases expect it.
-0
is a valid representation in floating point number system though.See: https://stackoverflow.com/questions/7223359/are-0-and-0-the-same
I don't know what
Test.assertEquals
uses, but as I already explained, there is no test case with a-0
.Unless one of the random test cases happened to be
0
?Math.floor(Math.random() * 101)
This comment has been hidden.
Why are you posting this as a comment? Even more so why as a suggestion? No message of what the code is for. Didn't even mention what programming language it is.
Hi @Deantwo I am new to codewars. Please let me know where I should be typically sharing sugessions? By the way its in JavaScript.
If all you want to do is post a new solution, just do the kata again. You can then upvote solutions that you think are good on the Solutions page.
Comments more used for feedback about the kata and reporting possible flaws or making suggestions to improve it.
And yeah, as I mentioned, comments don't actually say what programming language you did the kata in. So just posting a comment without being more specific can be very confusing.
Thank you so much for the update
This comment has been hidden.
This comment has been hidden.
Thanks, so nice kata!
The submit Final button is missing for me.
Not related to the kata, must be a website problem.
The website auto-scale in size depending on browser window size (including smartphone being rotated) maybe the button is hidden because the screen is not wide enough? I know some buttons vanish when this is the case at least.
Me too! I can't get it to work with any of my challenges
The Elixir test is wrong, perhaps you could update it to reflect the description?
Which test? there are litterally two types of tests and 6 tests in total.
If you mean the example test case then I already fixed it and it should be correct if you do the Kata again. EDIT: Don't know how or why, but I just fixed it, again.
simple check (2.3ms)
Test case make_negative(-42) == 42 is incorrect. broken.
Which programming language? Your post does not make a lot of sense.
Please tell me where/when you are seeing this error and which programming language it is for.
I corrected the Example Test Case for Elixir.
Thanks!
For Elixir the tests needs to be updated
assert make_negative(-42) == 42
, is not according to the description, expected result should be -42.And in the hidden tests:
Looking at the code I see no issue, but I don't actually know Elixir.
It clearly says
assert make_negative(42) == -42
in the test case. Where are you seeing this?The error I don't know anything about.
This is how the test appeared when I started the kata.
The issue from the hidden tests is a general one, I see it on other katas as well. I think they changed versions of elixir/OTP. So the tests need to be updated so people can submit their solutions.
I fixed the 'random' error.
If you have another issue, please make it in a separate comment/thread.
I can submit now. Thanks.
I corrected the Example Test Case for Elixir.
Is the second test case right? Shouldn't it be 9 instead of -9 somewhere?
The task is to return the input as negative, it is not suppose to invert the input. See the examples in the kata description.
So no, the test case is correct.
This comment has been hidden.
This comment has been hidden.
Oh boy, looks like I was up too late coding last night! I just learned about the bitwise operations recently. Looks like I got a little overzealous and conflated odd with negative. Cheers!
This comment has been hidden.
In Haskell, this kata is harder than in other languages, if one is not allowed to change the polymorphic signature that just mentions
Num a
and notEq a
orOrd a
. The description should mention whether adding more class constraints is allowed or not. If not, there should be test cases checking for this, and the kata should probably be worth more points.I have no idea about what your talking about. I don't know anything about Haskell, so I don't know what is up with that.
I can't change the test cases without admin help, and rasing the reward isn't an option because this kata is SUPER easy in other languages, so what is it you suggest?
Want me to just change the description to something like this:
I have no idea how data types work in Haskell.
I wasn't suggesting anything, I was just making a remark. If you want a suggestion, however, here it is. If this kata is meant to be super easy in Haskell too, then the type signature should be:
thus allowing the use of
<=
in solutions.That would require me to change what where? The Initial Solution?
Yes, that would be line 3 of the initial solution. It would have to be replaced by the line I mentioned above. This would not invalidate already submitted solutions.
Done. ^^
This comment has been hidden.
Oh, yes. I completely forgot that using only the two functions in
Num
might not be obvious for all. Luckily, all tests in the Haskell variant are instances of bothNum
andOrd
.on ruby it gives an unknown error msg. have no idea if my code works or not just an error msg.
Plenty of people have submitted Ruby solutions, so it most be your code.
This error can come up if you run test tests but there are no test cases present, which is the case in this kata :D Either hit submit to check if your code passes or create your own test cases
Wait, why is the ruby example test cases only comments? This is why I hate accepting code by others when I don't know the language.
Anyone wanna help me make a quick example test case? Here is the C# example test case as an example:
Would this work?
Submitted Java translation.
This comment has been hidden.
You're returning a boolean (True/False), not the number in negative form.
This comment has been hidden.
got it, thanks =)
Ok, solved it the hard way, but I'm learning.
One solution returned the number as a string. I think the data type should remain a number since that is what you would expect from a function like this. A string shouldn't pass because it isn't even really a number anymore.
Again about JavaScript? I don't know JavaScript, does JavaScript automatically convert
string
toint
?So
Test.assertEquals(0, "-0")
passes?@Deantwo: No. It passes if you use
==
orassertSimilar
.===
andassertEquals
also check for type equality. SoassertEquals
should be allright.Then I don't know what @ianwhitedeveloper and @tikitariki are on about.
This comment has been hidden.
This comment has been hidden.
In JavaScript? I don't know if JavaScript's
Test.assertEquals()
method makes a difference between0
and-0
, but I would be shocked if it does.Mathamatically it makes no sense for 0 (zero) to be negative.
See: http://en.wikipedia.org/wiki/0_%28number%29
This comment has been hidden.
As a beginner, I am just wondering, is my code just too big or takes too many lines ? Is it just experience that "shrinks" the code in ones head ?
I am guessing you mean your Python solution?
Well, you didn't need those variables, but most code is good if it works.
You can compare your solution with other people's solutions, this Kata can be done easily in one line.
This comment has been hidden.
Python translation kumited.
(krillgar have kumited a JS translation 20 hours ago) Description not modified, waiting approbation to modify it (add examples) and avoid collisions with krillgar version.