7 kyu
Filter the number
9,887 of 18,952matt c
Loading description...
Strings
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.
D translation moved from duplicate kata Get number from string.
Lua translation!
python new test framework is required. updated in this fork
Approved
Pursuant to this issue:
https://www.codewars.com/kata/55b051fac50a3292a9000025/discuss#64d41c95c734e70031455390
I've published a fork which replaces the (frankly ridiculous) JS random test generator with one which does not generate test cases greater than
Number.MAX_SAFE_INTEGER
. While requiring users to useBigInt
to correctly handle larger inputs would be better overall and more in line with other languages, doing so would invalidate the vast majority of existing JS solutions so I've chosen not to.https://www.codewars.com/kumite/64d435116fad180037ece9d4?sel=64d435116fad180037ece9d4
Would appreciate review/feedback.
Looks good to me. Just a remark: it's better practice to provide the input to user for failed tests (something like
failed test with value = ..., expected ... but got ...
).Seems like that would duplicate the existing output from the test harness, no? The logs are already in the following form:
Just return the numbers: expected <solution return value> to equal <expected return value>
.Oh, never mind, I misread! Have changed the test logs in the fork to report test input, too.
Approved.
2023 here. Can not get a JavaScript solution to pass the random test(s). I suspect that the random test case generator is creating test cases that can not be converted to values within the normal JS integer (Number) ranges. Example response:
Just return the numbers: expected 60908777950325700000 to equal 60908777950325694000
. Number.MAX_SAFE_INTEGER is 9007199254740991, so the test case is expecting a value that can't be contained in a variable of Number type. I tried throwing BigInt into the mix, but that didn't solve this issue.Confirming that this is an issue; for example the following input:
"d2888d05783d87bc88ff14c9e4d90e06"
filters down to:
"288805783878814949006"
yet the test expects instead the following
Number
:288805783878814960000
Due to floating point imprecision. I suspect it's sheer coincedence that many of the 7000ish current JS solutions work; they've just chosen the same imprecise method that the kata author did, so they all get the result wrong in the same way.
Good catch @mykalimba, I'll create a fork to resolve the issue.
Now fixed.
In Java I get a failed test for random
input string : 42ipio1262znstzbhi852389369152sbxc5 my ans : 4212628523893691525 expected ans "4212628523893691525" How is that wrong?
Your solution has a bug and crashes with an unexpected exception, it's not a kata issue.
This comment has been hidden.
I can see some of your solution, I do not knwo if it is the most recent one. And yes, I can see a bug in it, which would cause the crash.
As a first step to diagnose the issue, I would recommend recreating the failing test case in your local IDE and debugging trough it. Use your IntelliJ, Eclipse, NetBeans, or whatever is what you use for coding on your computer, and run your solution with the input which Codewars says you can;t handle. Debug through your code, find the place where it crashes.
You can also visit CW Discord and
#help-solve
or#java
channel.thank you
This kata is a subject to deduplication process here: https://github.com/codewars/content-issues/issues/154.
Please join the discussion to help us identify duplicate kata and retire them.
In JavaScript, I think the function name should be in camel case, not pascal case, no?
Yes, it should. Fixed.
This comment has been hidden.
Fixed.
You have to return a long ... that should have been mentioned.
This comment has been hidden.
This comment has been hidden.
I solved this kata by 3 ways:) Thank you
the description should mention that the number wont be signed
Ruby 3.0 should be enabled.
fixed
Java, C, C++, and NASM translations. Please review.
approved
Python 3 should be enabled.
Forked review and approve.
I've edited the kata manually. You should unpublish your fork or wait for somebody to reject it.
How can you do it guys???!!!
This comment has been hidden.
Hi! I can't seem to see why this isn't working. Any clues?
Thanks in advance!
Because you have the initalization of your arr variable inside your loop so it continues to get reset.:)
This comment has been hidden.
Uhmm..? When I try to run your code it doesn't seem it even work there's an error with the for loop?
I've tested your code and after you fix your for loop you need to return a number not a string. So convert your result into a number and return that when you do that it should work :)
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
your outputs are wrong, basically your result calculation isn't just concatonating the number, the idea is to just remove all non number values and convert it to a number. Also please resolve your older issue because this is the same issue.
I disagree that my output is wrong. We can Number(string.replace(/^[0-9]/g,'')), but that still gives us a value that is NOT achieving the stated goal of the Kata. The goal is to 'return ALL the numbers in the string in the order they occur,' emphasis mine. The solution checker does not do this. I will mark my newer issue as resolved, but I do not think this Kata is correct with the current goals or test cases.
Either the test cases need to be fixed to actually meet the goal, or the goal needs to be changed to meet the test cases.
I don't mean to be obstinant, and thank you for making the Kata, but we should not have people train on wrong outputs.
You're evaluating the number as you add it to your result, when you're supposedto evaluate the numbers when you return the result...
This Kata will not work for JS with the current test cases: The max safe int is 2^52 or: 9007199254740991 Several test cases run well over that. This Kata does not accept stringoutputs and does not correctly test its own input for JavaScript. Please fix test cases for JS; even the testing program itself is broken, see below.
Running a test to print out the input value and the output the automated test expects from us we get: Input: ae410d57182d3cb7cf41bbde0fd658f2 Output tested for: 41057182374106584 Despite the fact that all of us can clearly see it should be: 41057182374106582
Another, more obvious test: Input Vale: db8d1b5149a0371b2b603095d969c1ac Just return the numbers - Expected: 815149037126031000000
Despite that it should clearly be 815149037126030959691
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER
I think you're overcomplicated it, you're supposed to return a number even if it is over the Max Safe Integer for Js, I know the precision is off but it shouldn't matter. The whole idea of the kata is to just filter out everything that's not a number. If you post your solution and mark it as a spoiler I can tell you where you went wrong.
I'm going to makr this issue as resolved since you haven't responded to this issue.
tests don't pass (Python):
File "", line 8 Test.describe('Fixed Tests') ^ SyntaxError: invalid syntax
It works fine to me and I see many users did it, so I assume there is something wrong in your code, like an open parenthesis or something like that.
If you need further help, please comment under my post below, so that I will get notified :)
Translated it into both Ruby and Python, if you want to accept them :)
A small note: you didn't specify how to behave for strings with no numbers, so I assumed each string must have at least a number; let me know if you thought otherwise and I'll fix it.
Also, nice testing code you created for the JS version :)!
Sweet, I'll accept them now and yeah, all strings should contain atleast 1 number. Thank you very much for translating the kata :)
My pleasure and thanks to your for your work :)
Don't use
string
as a variable name please. It shadows things likestring.digits
that might be useful.You can still change the name of the parameter, can't you? And I would use something else instead, but I see your point.
This comment has been hidden.
I don't really know why it doesn't work but I recommend using a different method to find out if the value is a number or not.
Please, always format your code (triple backtick before and after it), as it makes things much easier to read.
Your code returns a falsey value for 0s and can't work for values which are not decimal numbers; at matt stated, I would test for numbers otherwise and there are plenty of ways, from regexes (do yourself a favour and learn them soon if you don't know about them), from merely checking if the given value is in the array
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
.This comment has been hidden.
Got it! Thanks everyone for your reply.