7 kyu
Incrementer
4,621 of 11,981kkavita92
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.
This comment has been hidden.
This comment has been hidden.
When it comes to language, right there I thinking, thanks.
This comment has been hidden.
There's literally nothing wrong with using mod operator. Unless it has different behaviour on certain number in your language?
Just tried it on the language you used, PHP. Nope, nothing different. There's nothing wrong with using mod.
Not a valid kata issue, marking as resolved.
This comment has been hidden.
C
Description says "return an empty array if your array is empty", but tests require null to be returned.
This comment has been hidden.
Read the description again:
And specially the last example.
The test is fine:
Go, not fixed:
emptyArr
isn't initialized, so it'snil
.Why don't the damned tests get updated when I fix them? Here is a fork without
emptyArr
(please note the only difference with the current version is one empty space removed): https://www.codewars.com/kumite/62849559f46db63866daaa6a?sel=628526c82f9a232ffcf2b0dcGo:
(Since nil slices seem to be idiomatic in Go, both probably should be accepted.)
It is the same thing in all katas expecting arrays in Go. It makes no sense to tweak something out by myself here because it's a general framework issue IMO. Slice outputs must be initialized using
var arr []...
or tests will fail on empty result. I do think this is not a kata issue (I've experimented in many different katas) and this should be raised at a higher level.Whatever kind of issue it is, it's still an issue. If only
nil
is accepted, it should be mentioned in the description.Obviously, polluting multiple descriptions with such a mention is not a satisfactory solution.
Fixed with a crappy tweak.
(author is inactive)
approved
Excellent kata
please i cant figure out where my code is wrong on this kata.i need help .
I'm looking at the tests and they do not match up with what is expected from the instructions. I have tested locally on my own IDE and have receive the expected results according to the instructions. Please fix so this can be completed properly. I was using the Java language.
All tests are working correctly. Not an issue.
Instructions are a bit inaccurate with regards to what is asked, for example instruction asserts that 'return an empty array', but you actually have to return NULL.
State the language, is it C?
How does [2,4,3] result in [2,4,6]? I must be misunderstanding the question completely. I wouldd have thought it should result in [3,6,6]]
I think you're misreading something, maybe the error you get is
[2,4,3] should equal [2,4,6]
? In that case[2,4,3]
is what your function wrongly returned, not the input value.The tests in the python version of this kata do not return accurate results.
1,350 solvers in Python, so that's unlikely. can you provide some evidence / examples?
Maybe I don't understand the logic behind the kata. If you look at this sample test- "[2, 4, 6, 8, 0, 2, 4, 6, 8, 9, 10, 11, 12, 12] should equal [2, 4, 6, 8, 0, 2, 4, 6, 8, 9, 0, 1, 2, 2]," my understanding of the logic behind the problem suggests the output list should be [3, 6, 9, 0, 4, ect.] Why would the list remain identical instead of incrementing the digits in the list based on their position? The sample test apprears to ignore the first 10 elements in the list.
[2, 4, 6, 8, 0, 2, 4, 6, 8, 9, 10, 11, 12, 12]
is not equal to
[2, 4, 6, 8, 0, 2, 4, 6, 8, 9, 0, 1, 2, 2]
You are ignoring the last
4
elements of the list.The test is correct, and correctly failing you. Read the description carefully ( and fully ).
Failure messages of the form "
$ACTUAL
should equal$EXPECTED
" mean you actually, incorrectly, returned$ACTUAL
, and the expected answer was$EXPECTED
.( So you are quite close to the correct solution. )
Still not seeing it...I'm all gooned up on the logic here. I've reread the instructions a zillion times. I see the last 4 elements in the list (based on position starting at 1) to me should be 21-->1 (e.g. 10 incremented by 11), 23-->3 (e.g. 11 incremented by 12), 25-->5, 26-->6 (e.g. 12 incremented by 14) and so again I don't understand why the first 10 elements didn't increment by one digit and the last 4 elements incremented based on their position (w/ two digits). Obviously I don't understand what the kata is asking me to do...
[2, 4, 6, 8, 0, 2, 4, 6, 8, 9, 10, 11, 12, 12]
should equal[2, 4, 6, 8, 0, 2, 4, 6, 8, 9, 0, 1, 2, 2]
means that your function returned[2, 4, 6, 8, 0, 2, 4, 6, 8, 9, 10, 11, 12, 12]
, but it should have returned[2, 4, 6, 8, 0, 2, 4, 6, 8, 9, 0, 1, 2, 2]
instead. The original input for that test is[1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9, 9, 9, 8]
. Your function works mostly correctly, but there's something in the kata description that you're missing that is causing you to fail.Haskell translation with description spelling erorr fixed.
Approved
I think the tests are wrong. When verifying that the code is working, the tests do not match the tests in the test function.
Please provide an example of what you're saying.
Java translation
approved
C# translation
Approved.
COBOL translation (author inactive).
approved
Check input on second test for python: [,1 2, 3] would be iterated as [1 2, 3]
In random tests, it throws an error (#<NoMethodError: undefined method `expect' for main:Object Did you mean? exec>), although normal tests pass just fine. What is the reason? Ruby.
updated, along with python test framework
The Ruby version description is using curly braces for array instead of square brackets.
There is/was no ruby-specific description. Anyway, I updated the description to be a bit more clear
Please, C Translation Please, NASM Translation
approved
Thanks!
C++ translation translation added :)
Approved, finally
Thanks a lot! You are a very helpful guy
This comment has been hidden.
Don't mutate the input array.
Well, now it's been fixed in the test suite, but it was because of that.
Answered by Chrono.
Hi, I'm trying this kata, but it seems that your tests are wrong with the numbers higher than 10:
it("Testing for [4, 6, 7, 1, 3]", () => assert.deepEqual(incrementer([4, 6, 7, 1, 3]), [5, 8, 0, 5, 8])); it("Testing for [3, 6, 9, 8, 9]", () => assert.deepEqual(incrementer([3, 6, 9, 8, 9]), [4, 8, 2, 2, 4])); it("Testing for [1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9, 9, 9, 8]", () => assert.deepEqual(incrementer([1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9, 9, 9, 8]), [2, 4, 6, 8, 0, 2, 4, 6, 8, 9, 0, 1, 2, 2])); });
the first one should return [5, 8, 10, 5, 8], the second one [4, 8, 12, 12, 14] and so on. Can you fix it so I can complete it?
Thanks!
^ That
Sorry, I forgot that part! :) thanks!!
This comment has been hidden.
try with
[4,4,4,4,4,4]
TypeScript translation PHP translation Julia translation
It should be properly mentioned that arrays are
1
-based.👆
That's a terrible wording, and it should be changed.
JS: why the hell are there a random number of random tests...!?? XD
I don't see a random number of tests. But I did make some improvements, such as enabling Node 10 (which measn using chai too), performance things, and added a bit more random tests...
Didn't look at the test suite before you changed it, but considering the number of random tests was varying from one run to the other... ;o
Well, sounds handled anyway. Thx.
The input was mutable in random tests in javascript. Already fixed.
CoffeeScript :coffee:, Crystal :gem:, Python, and Dart :dart: translations kumited, please review and approve :smile:
Bump.
Please, pass a copy to the user's function to avoid problems with input mutation, and you also missed :snake: for Python in this post :wink:
Fixed in all languages.
Well, I didn't know about that emoji :wink: edit: lol found an emoji for PHP: :elephant:
@Chrono79 But reference solutions are called before users' solutions, so ownership can be passed safely (and in Dart I think List is immutable), so what's the difference?
@Unnamed: Not for javascript (Steffan already fixed it), see the current first post, I though maybe some of the other translations could have the same problem (didn't check).
I posted it here so those other translations were checked and also for the snake emoji.
There appears to be an error in the random tests; here is your random input array:
[ 3, 9, 5, 7, 6, 2, 2 ]
then I get this error message:
Incorrect output - Expected: '[5, 3, 1, 5, 6, 4, 6]', instead got: '[4, 1, 8, 1, 1, 8, 9]' <== my answer
But it looks like my answer is correct...
true, for some reason my function only works on basic tests, not random tests. sfoulk, please put the issue label on your feedback
What is the issue label?
Hi, when I run my code, it passes in all sample tests, but it fails in all random tests. In console I see, that it just doesn't add counter to numbers in array in random test, but, still, it does so in all sample tasts. May be it could be some mistake in random tests? Thank you.
Exactly the same problem for me : sample tests all OK, random tests leave the array unchanged. Thanks for your help !
My friend @dastevens gave me the explanation. My solution works on the sample test and not the random test because I changed num without knowing it. Why ? In my solution, I wanted to work on a copy of num, so I wrote :
var numInc = num
But in Javascript, var numInc = num does not create a real copy : it just copies the reference (address) of num in memory. As a result, any operation on numInc will also modify num itself.
(This would not be the case if we worked on strings, since strings can never be modified).
And this is why, we think, the sample tests are passed but not the random ones. Let's say that the author wrote a function, the solution of the kata, named "kataSolution()" ;
the sample tests do not run kataSolution(). The expected result is already provided. The tests only compare this expected result with that of incrementer(). In that case everything's OK.
but in the random tests, kataSolution() has to be run, to calculate the solution. And it seems that it is run AFTER incremeter(), which modified num. So kataSolution is run on a modified num. Example :
num = [1, 2, 3]
myIncrementer(num) = [2, 4, 6] , but it also transforms num in [2, 4, 6].
so kataSolution(num) is in fact kataSolution(myIncrementer(num)) ! That's to say [3, 6, 9] instead of expected [2, 4, 6].
We suggest changing the description to say do not change the input array, and add a test that fails if the input array is modified.
Thanks to the author and to dastevens to make me realize this noticeable feature...
This comment has been hidden.
Simple and fun Kata but your Description examples are incorrect - they make it appear as if the user function receives a variable number of arguments instead of exactly 1 numerical array.
Urgh silly mistake - fixed!