6 kyu
Is Integer Array?
4,962 of 7,032ravikiranj
Loading description...
Arrays
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.
Input: [1, 2, 3, 4]: False should equal True Log [-11, -12, -13, -14] -11
Lol, idk but input of test and logs of input array are not equal, not possible to solve it, nice bug
This comment has been hidden.
Tests often input not array
Should be 7kyu at most
Description should be language-agnostic
Fixed in this fork
Random tests in Ruby should generate inputs other than lists
DONE
python: random tests are attackable.
Fixed in OP‘s fork
python new test framework is required. updated in this fork
Approved
really wish that these mixed types situations that only js users seem confused over wouldn't be translated to anything else, it's not applicable..
More challenging than anticipated by looking at the description, but not a 6 kyu. I'd consider it a hard 7 kyu. Regardless, difficulty rating cannot be changed.
This comment has been hidden.
I think what the question means is a floating point number like 42.0 or 3.0, where the value after the ones place is zero? (the desc was a little wierd)
This comment has been hidden.
I think, one Sample test case is wrong [1.0, 2.0, 3.0001] - Expected: false, instead got: true This array contains all float objects, still It expects false
Read the instructions again.
This comment has been hidden.
There're more than 5 tests. Your solution is wrong, not an issue.
Ruby 3.0 should be enabled.
done
why would u want a None value to return False?
This comment has been hidden.
Can't be changed.
Ah, okay. Thanks.
This comment has been hidden.
you need to take care about empty array
Not sure if I'm missing some logic in the instructions, but when doing the random testing in Ruby I don't think the output should be expected as true here as the array contains nil right?
" Testing for [71, 54, 5, 538, 8, nil, 2, 233, 1, 154, 4, 49.0] It should work for random inputs too - Expected: true, instead got: false "
Just ran this test and my solution passed with no errors, yours too, but you had other bugs because you are computing
arr
's length whereasarr
can be an integer itself, which does not have thelength
property. (Not a kata issue nonethelessThis comment has been hidden.
This comment has been hidden.
Prolog translation kumited, please review.
Rejected by someone :-(, Do publish a forked version with a new suggestion ! ^^
That's fine. It wasn't a good translation anyway.
This comment has been hidden.
Definitely, should be 7kyu
Ruby:
Fixed
No random tests and the solution below may pass but not fit the problem description:
https://www.codewars.com/kata/reviews/5e0e15bd4225f300010c2a9f/groups/5e0eb5644ebc200001b5d8fc
test added to all languages
random tests => duplicate issue, (but only in js) see below, thanks
This comment has been hidden.
Because your solution is wrong. Read the error message.
no its not wrong i test my solution many times!!
console.log
the inputThe description should be made language-independent, and the specifications rewritten, at least not to use CSS inside code blocks.
done
So is it
isIntArray
oris_int_array
?Also, why are the specifications in a code block?
I think the camelcase vs snake case depends on language convention of used language. For example, in general, JavaScript uses camelcase but Python uses snake case.
Done. (Surely you could just edit the kata add 2 words to the desctiption rather than raising an issue. It would take less time too.)
Second point isn't an issue
So which one should I implement? Do you even know how to fix the description issues?
And highlighting code with italics/bold is unreadable, so that's bad too.
But that's dumb, and shows that whoever wrote the description can't explain such a trivial tying in a language-neutral way, and CSS mark-up doesn't work inside code blocks, so it looks bad too.
Not one person below has been confused about the name of the function.
If you really think this is a problem, then you can change the description yourself.
The main.py file (which contains content I did not create--I assume it executes the code that's submitted) contains a call to xrange(). This causes an error when using Python 3, as xrange() is no longer built-in. Submitting code against Python 2 works, however (since xrange() is built-in for Python 2).
Fixed
Python test case #5 is not integer.
Python tests contain floats that are expected to be treated as integers. edit: also, python description uses js syntax
Had the same problem.
Fixed
Input: [1.0, 2.0, 3.0]: False should equal True how??this is float class then why True?
True if all are float or all are integer, read the instructions
Ruby:
Test.assert_equals(is_int_array([1.0, 2.0, 3.0]), true
That's not what I consider "is an integer" by default in a language that has an integer type. If this behavior is intentional, the description should be more clear about it.Fixed. Thanks.
No random tests! (Javascript)
Fixed in this fork
This comment has been hidden.
Not all input values are arrays (or strings) that have length property. In your case the passed value was null (it's there in the error message).
but how i do not get it
Before using length, check the input is really an array. Check MDN Docs
I finish it,finally.I am so happy.[比心]
I meet the same problem. TypeError: Cannot read property 'length' of null at isIntArray at Object.handleError at ContextifyScript.Script.runInThisContext at Object.exports.runInThisContext. But I made the code pass all the test cases successfully.
The input array is null.And
null.length
will have exception.There are still many testCase before submit.
You can use
console.log()
to check what "arr" is.Thank you ,so much.I will have a try.
Not a kata issue.
Finally Got it, we need to check null, undefined and if input is array to get test case 9 right.
same problem
My code:
function isIntArray(arr) { if(arr == []) { return true; } }
is returning "undefined" on the first test - how??
Wrong:
arr==[]
Right:arr.length==0
Because in JavaScript
[] == []
returns false - you cannot directly compare arrays. I suggesting reading this or this for information why. If you are checking an empty array, I suggest using Boolean, e.g. if !arr or arr.length==0.Edit: Fuck, jinx beat me to it again :P
!arr
would be wrong too. Array is an Object and any object is true-ish.Ruby and Python translations submitted, if you want to approve them :)
Approved :D
This comment has been hidden.
You cannot within
.map()
, as areturn
statement just exit the relevant function, in this case the one inside the.map()
method.If that is your goal, you might wish to use something like an ordinary loop, iterating over the array.
Why not use .every()
The test cases are missing truthy non-array inputs. Many solutions will fail for e.g.
true
.Added across all languages
Interesting kata, especially the test cases on submission, you think you have success but then see a fail, test 9 was very interesting due to the confusing error message, but got there in the end, thanks.
the test case faild at input:'' ? how to check this ? -- I got this same error.
I think this may be a bug. I did some testing in console and was not able to reproduce. I wish we had the option to view test cases after passing X% of tests or something. Not having more descriptive messages is very frustrating and makes users feel confused as to whether they made a mistake or the platform is acting wonky.
the test case faild at input:'' ? how to check this ?
Hi guys, I'm looking for some tips regarding the 1.23e-7 input. I tried to convert the exponential number with .toFixed() without success and I can't find a way to check if the number is exponential or not ... Thanks for your time.
You should just check if it is an integer, in which when divided by
1
will yield0
. There are also built-in functions that can do such checking.is 1.23e-7 an integer?
1.23e-7 is scientific notation for 0.000000123, so no, it isn't an integer.
It says "Input: [null] - Expected: false, instead got: true"
However, @jsfiddle.net, it correctly returns false, if input is null.
Anyone have an idea as to what may be making the difference?
A little late but the input is not
null
but[null]
This comment has been hidden.
This is not an issue. The problem is with your code. You defined your
sum
variable outside the function, so it's global. It needs to be defined inside your function so it's a local variable..
This comment has been hidden.
Try using console.log(arr) to see what is getting inserted into each test. The results might be surprising. ;-)
The test fails on -1 saying it has be false while my solution is giving a true. -1 is an integer Ignore-- did not see that the test case was '-1' :)
I made the code pass all the test cases successfully, but I keep getting this... TypeError: Cannot read property 'length' of null
Could anyone help me out please?
same problem
same here..
Try using console.log(arr) to see what is getting passed to the test values. You may have to account for unexpected types of input.
Your solution has to return
false
for every input that isn't an array of integers.I.e. if you pass anything that's not an array into the function, it should automatically return
false
. All of the following should return false:This is an issue, I have the same problem. I put my code into REPL, tried every possibility, and everything worked, but my code throws an error when I try to submit it on here.
This isn't an issue with the kata, you are supposed to return false when the array isn't an array.
This comment has been hidden.
i am using isNaN function for this kata, but it keep give me false when the input is NaN. what is wrong with the function?
Well, it shouldn't return false in that case. Could it be that you are expecting a value to be something else? For a more elaborate answer you can post your current code in a comment and mark it "Spoiler content".
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This kata has the best tests I have seen so far, I love it.
Isn't
1e+308
considered an Integer? It's expecting false for this testYeah, that's definitely an incorrect test.
This comment has been hidden.
My bad. you are right, +1e308 is an integer in a mathematical sense. I will correct and update the tests.