Retired
Find the 2nd largest integer in array (retired)
327 of 1,078nakulgupta18
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 kata is a subject to deduplication process here: https://github.com/codewars/content-issues/issues/132.
Please join the discussion to help us identify duplicate kata and retire them.
Retired.
Can anyone help me? Basic tests pass, random tests fail. Here is an example result:
Why is it not working? After all, I have the same result?
Are you mutating the input array? Hmm, no, something seems to be broken.
I only read the input array, and print as a string f"Input array: {arr}". I find the 2nd largest number and return the result as an integer. Tests shows 'Assertion OK' but print Result = 'number' which is the same result as my 'number' is not OK. Strange. Can I paste my code here? I'll show you then.
I guess you could, but my own code also doesn't pass the tests and gives the same result as the expected one. We'll have to wait one week until I can check the tests unless @FArekkusu can check them before.
Many old katas are broken due to a recent change in how the test results are interpreted by the system. This one is fixed.
Thanks for the response and for fixing this kata. Now it's ok :)
Added improved JS translation. Review and accept, please. Thank you.
JavaScrpit translation is ready for review. (some how this is buggy version, it dose not have
JS selected
. Added new well working forkThis comment has been hidden.
You are not filtering non-integers, just skip them, but they stay in the array. Thus when you sort it, you get the error.
Oh, and next time put your code between triple backticks (```) so it stays formatted
For the Python users, there is a problem with the definition of Nil...
Nil is not a defined statement for the language. So I had the function return Nil as a string and had to change the expected in the test cases to expect "Nil" as a string. So, change the test case expected in the bottom window.
Then, Nil isn't an expected return in the final cases, it says to expect None. So when you go to do the final tests, change the function to return None and not "Nil". None is a known statement in Python.
Looks like there is a fork coming up for it but in the mean time you have to mess with the Kata a bit. The rest of the Kata is up to you!
To clarify the issue: python random tests correctly expect
None
if there is no solution; however, there is a wrong sample test that expectsnil
, which would be a variable in python...Nil is not undefined, what might be the problem here? I tried to return None,empty list and 0
Solved: just declare nil before function
It's a typo in sample tests. There's a fork with a fix but someone need to approve it. Regards, suic
python:
test.assert_equals(find_2nd_largest([1,1,1,1,1,1,1]), nil, 'expected nil')
(lol...)tho:
1 should equal 3333333333333333333334L
-> except that in python 2, that's not an integer that's a long (ok,, I'm nitpicking, here. But what's the point of having this difference only because of the outdated opython version...?)correction: the issue is actually that the default version is set to py2 while other versions are available. So just select the good one in the edit panel.
I've approved it, but there was a typo in sample tests which I oversaw (nil instead of None). :/ There's a fork with a fix, as the author disabled contribution. Can you please approve the fork?
Feel free to fork and make other changes.
Thanks,
suic
@B4B: Have you got notified about my previous comment? Regards, suic
Nope, didn't got the notif'. I'll look for it.
My code seems to try to return 'nil' in all the right cases but "NameError: global name 'nil' is not defined" is generated. Not sure what to do about it.
ruby
nil
<=> pythonNone
No random tests.
...in ruby, and no sample tests either.
Python translation kumited
There should be a test case where the array elements are Bignums to catch people who filter on Fixnum
this kata is meant for beginners with a lil logic. so no bignums.
@nakulgupta18: This choice may make the kata somewhat inconsistent between translations due to boundaries between numeric types in different languages. In Python, for instance, both plain integers and long integers are tested. A refinement of this kata might remove this inconsistency.
typo in text description "hten" should be "then"
resolved thanks
Tests give no information about why they failed.
resolved thanks