5 kyu
isInt32(int, byteLength)
122 of 123wthit56
Loading description...
Bits
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.
How is int(10) and bit length = 5 Test Case expected to be False, Ten in binary is 1010 and the bitlength from the Least significant bit to Most significant bit is 5 , so there is no value after . The test Case should flag True.
byteLength
should be renamed; "byte" != "bit", and they should not be mixed.Input validation is not properly explained. Missing information about handling
null
andundefined
length.unclear case
Seriously needs example test cases. It's entirely far from obvious from the real test cases what's expected and why something is wrong, and it doesn't help that the test case size is so big every time I submit my code my browser chokes for like dozens of seconds.
Hey there! Good suggestions. I wrote this a very long time ago and have become much better at writing these katas in the meantime (I think).
I've added messages to each individual test, added step-by-step examples to the description, and added those examples to the example test fixture to get people started quicker. I've also reduced how many randomised tests there are (though I'm still not sure why they are so slow for us; there weren't really that many).
Hope this helps! Tom.
Hi there.
Your test code never tests the boundary condition where
byteLength = 32
andint
is a negative number.i.e.,
isInt32(-448, 32)
Because of this my first solution is so wrong :-(
Adding something like
test(-5, 32);
to your test cases will be cool. And perhapstest(5, 0);
andtest(-5, 0)
also.And may be change
Math.random() * 32 | 0
toMath.random * 33 | 0
so there is a chance of hitting 32 (since there is already a chance of hitting the other boundary, 0)Awesome kata btw.
It seems that according to the tests run that giving a decimal value that is equal to an integer (e.g. 10.0) returning true is ok. Is that what is intended?
In memory, 10.0 and 10 are the exact same value. If we're talking about JavaScript, that is.
Indeed. And 10.0 converted to string came back at "10" - so I was really scratching my head as to how to identify 10.0 as a non-integer!
I was obviously more picky than the kata demands :)
Or more picky than JavaScript, I guess ^^
When I test my code in labs.codecademy I get the value that is expected. When I submit it on codewars I get the value that isn't expected. What could be causing this? It's the same code and I use the same test example values.
No idea, I'm afraid. Could you paste in your code in a ``` code block ``` so I can take a look?
This comment has been hidden.
also i only started programming 3 months ago so keep that in mind!
What values were you testing with on codecademy? It looks like you might not be handling
null
andundefined
byteLength values in your code... They should effectively behave as ifbyteLength = 32
.This comment has been hidden.
Something useful for finding out what's going wrong would be to log out the inputs (the
int
andbyteLength
argument values) for each call. Then you can follow through your code with those values and figure out what it's not doing, or what it's doing incorrectly, to make it fail the test.As I say, for the code you've shown me you're not doing any kind of check for when
byteLength
is null or undefined. You're only comparing things to byteLength as if it were a number. If it'snull
for example, your code would effectively treat it like the number0
, which wouldn't be correct.This comment has been hidden.
Having
null
as default doesn't correspond to es6 semantics.I wasn't trying to correspond to any ES6 semantics. This was made before ES6 was well-established, and I don't believe ES6 has functionality to check for bits only within
byteLength
of the end, anywa.This comment has been hidden.
Yeah, I can see what you're saying. Tweaked to "will be a primitive integer from 0 to 32". Works better?
on second thought, you should be OK: http://english.stackexchange.com/questions/7871/between-a-and-b-or-from-a-to-b
(SQL has the keyword "BETWEEN" as inclusive by default). so no worries - it's up to you.
This comment has been hidden.
Not sure to take that. Are you saying I should stop writing kata, because no one else is interested?
I may well check out your katas at some point, but I'll do that in my own time, if I like your solutions or whatever. I don't appreciate you spamming my kata with "don't bother" and "check out my stuff instead". I appreciate you taking my kata and ranking them and and such, but I can't see how you're not being a little aggressive with this comment. ;/
I apologize. Definitely not the right place to write that, but not really much other place to write that (so I will downvote my own comment). Codewars seriously needs a PM system for this kind of communication.
When I said "you are probably learning more from your bit katas than anyone else," I'm not saying don't bother. I'm saying you're accounting for the edge cases you're learning by publishing a lot of bit-focused kata. While the people solving them may forget the edge cases once their solution passes, you'll still have them baked into your head from all of your authoring. I consider that to be a good thing for you, and for the people that are learning themselves a bit more (pun totally intended).
I enjoy your solving and ranking your katas, just was wondering what you would think of mine.
Again, apologies. My comment came off the wrong way.
Okay, I see what you mean. Just a bit too sparse to convey what you meant, I guess.
As you say, I do have fun writing these kata. In fact, when I want to investigate an idea I have, instead of simply writing it offline for fun, I go straight here and build a kata around it. It helps me focus on what features should be handled by the function or whatever, and what edge-case tests I should employ to ensure it all works as expected. Plus everyone else on here get to try building the same thing. It's awesome when someone comes up with a valid (non-cheating) alternative way of doing things and teaches me even more about the subject I'm investigating.
I'll take a look at your stuff when I have time; see if I can code up some interesting methods for you to peruse, too ;P
Before starting, I would recommend right-to-left be aka most significant bit to least significant bit.
Edit: I mean least significant to most significant?
Er... yes. I mean... that's how things work with JavaScript integers. I've noted that in the kata for how to count the "byteLength". Were you suggesting I change something to make it clearer?
This comment has been hidden.
Yeah... another bug. Kinda wrote this kata in haste, I'm afraid. Thanks for bearing with me.
I've fixed the bug and added an explanation of what to expect as
byteLength
values.Its all good. My code passed after you fixed the bug, but I accidently clicked submit before I cleaned it up, so it looks absolutely attrocious. haha
Also, the byteLengths between 0-32 is good. I feel it is probably good to go now.
Ah-- cool. I do that sometimes ;P If you click "Train Again", there's a tab on the left with your "Past Solutions". I often copy my old code out of there, paste it into the box and clean it up. ^^
This comment has been hidden.
I've added some description to the
int
parameter explanation. Does it make things clearer?As for negative numbers, you're spot on. ;P
This comment has been hidden.
No; that was a bug. Thanks for finding it! ;P
A "byte" is basically a group of bits. So the byte length is how long the byte is, or the number of bits that make up the byte.