You need to sign in or sign up before continuing.×
6 kyu
Typer.js
673 of 887Jim-Y
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.
Object
team anyone? I'm surprised almost everyone follow the pre-written codes and use an IIFE instead of just creating an object.NaN
is a number too. If you wantisNumber
to returnfalse
instead, this has to be mentioned somewhere.This comment has been hidden.
for some reason
def self.is_exception?(arg); arg.is_a? Exception; end
didn't work for me. What did work was to traverse the whole tree of classes which descend from Exception and then test the arg's class against that whole list.CoffeeScript initial setup of typer does not match JavaScript version.
NoMethodError is_a? Exception => false , so Many previous solutions is not right. Test cases should be improved.
I don't think is a good kata..
Hi, I am using Ruby and I found the following codes would pass the Test Cases.
def is_number? a; a.is_a? Fixnum; end
The Numeric type includes
Fixnumb, Float, etc
so more Test Case shall be added.Ex:
Test.expect Typer.is_number? 5.0
This comment has been hidden.
Something strange with tests in this kata. When I do Run Tests everything green, but when I submit it gives me: failed on number literal arg. failed on Number constructor arg. failed on casted to Number arg.
What does it mean, can you decifer? I have no idea how looks test cases I've failed.
Yeah, I get that error too
Only one fail
failed on Number constructor arg.
What to do? I can't pass number testing, so frustrated!!!Translation in Ruby added http://www.codewars.com/kata/typer-dot-js/translations
What's the point of testing 4 "different" undefined values. They're indistinguishable for test function.
Maybe those tests are useless, but gives higher coverage, and they doesn't affect the possible solutions anyways. But good points there, thanks. I will review them.
Sorry, I don't understand how four tests can give better coverage comparing to one test. I'm not saying all four to be removed.
I mean, when I was creating the test cases, I wanted to cover every possible cases to generate undefined value, either by passing an explicit undefined, or passing some expressions which will generate undefined implicitly. (or at least cover some of these cases :)) It can be that since every expression will generate the same undefined value, creating 4 tests were needless...
From the tests:
I think this test case is misleading. isNumber should return true for NaN values and this is ok. Since NaN is number (links to the EcmaScript spec: Number type, NaN)
Anyway, this thing about NaN should be mentioned in the description.
HI, i got stuck with this kata. All test i have done are running fine, but when i submit it i get "failed on String constructor arg!" error.. Never used JS before so i am not even sure where to start? Any suggestions would be great.
Thnx
It seems your
.isString
method doesn't recognize a string created this way:new String('a new String')
ie usingString
as constructor.By the way, there're more than 50 other test cases after this one. This kata is average ranked 6 kyu, if you really never used JS before may be you should try to solve easier ones before.
Thnx for info... any1 suggestions for easier kata?
OP solved it, closing
Needs a better description of the methods to implement.
Modified description. Being more precise on method description would mean a so big hint, that the apprentice wouldn't take any time searching for possible solutions, since everything would already be in the desc.
This comment has been hidden.
This comment has been hidden.
Arrays are Objects in Javascript, so:
should return true.
Returning
true
forisObject([])
would be misleading, say i want to check ifvar myObj = {prop: 2}
is object, then performhasOwnProperty
on it would lead to unexpected errors. Otherwise, I understand your concept, maybe the name isObject is misleading, isPlainObject would be better.Then you're going to have to define "plain object" in some strange way that's not exactly congruent with the Javascript language as it stands. Not that I don't see your point; it's just that if JS doesn't make the distinction, then a base type-checking library shouldn't either.
After all, i'm still not convinced why
isObject
should return true for[]
. Could you please be more specific? Maybe my description was bad to use the word type. I think a functionisArray
should check if the argument is an array,isObject
should check if the argument is a JavaScript object, not OOP object. I don't know if you are familiar with jQuery, but according to the reported issue,$.isEmptyObject
should returntrue
for[]
since [] is an object, and empty. But its not the case. What do you suggest? Remove isObject method from the kata, or the tests should pass on isObject with an array as argument? That wouldn't make sense imho :(I'd advise simply explaining what you mean by the different "is"es. Other good ones to describe would be things like Boolean and Number; should they include "boxed"
new Boolean(true)
or not, that kind of thing.isObject
should returntrue
for[]
becausetypeof [] === 'object'
. The only thing that should returnfalse
withisObject
is a Number, String, or Undefined (and possibly null). Everything else is an object (even functions technically).I suggest you either scrap
isObject
, or descibe in detail whenisObject
should returntrue
orfalse
. The problem is that the wordObject
can mean many different things. Good luck :)Hi, thanks for the suggestions, i updated the description, i hope its more clear now. Please provide more feedback if you have time ;)
This comment has been hidden.
Partly agree. I agree that it is JavaScript which is a dynamic language, it was not designed to work with types. But, this site, and this kata is not intended to be a reference for type checking, it only covers an uncommon case/task in JavaScript. Maybe checking if new String(smtg) is Object or String just doesn't make sense, but we can do this, and i think its worth to make a kata around this issue. There are plenty more katas here what only reflects to one of JS's uncommon features and the warriors can profit from them, not because they are advised to use it in prod, but they will see these cases once in a while. Thats my opinion :)
Btw i did this kata TDD style, i first wrote some ~50 test cases, then made the default "solution".
This comment has been hidden.
See, and that's where I disagree. Javascript is a prototypical language, and as such is heavily reliant on types, it's just that the types are highly mutable. Since this is a fairly basic kata, a lot of people completing it may be learning the language, and I don't think we should be teaching that Strings and Numbers aren't Objects.
Beyond that, since JS doesn't support your typing definitions, your requirements aren't (and can't be) consistent with the language. You say isObject should return true for Object.create(), but Object.create() can create any type of object. For instance:
That's an empty array. Barring re-writing Object.create, There's no way of knowing how the empty array was created, just that it was, and you have it. The current requirements have this case as Schrodinger's array: isObject must return both true (made with Object.create) and false (is an array).
Hmm, you have some point. I really don't want to let this topic go, since this really bothers me, and my mind, but if it is misleading to new learners, then would be happy to delete this kata, than making bad intentions in newcomers. If some more people will vote for a drop, i will drop this.
Question: Are you satisfied with the conventional ways for type checking?
Maybe it just me who are not satisfied enough with the ways we validate input arguments now :) I know, i know, TypeScript, Dart, other transpilers... :)
This comment has been hidden.
I modified the details, i dropped isObject, but also mentioned it :) Thanks for the advices. Also if you have some suggestions for the tests/etc please provide ;)
Your tests look thorough to me. :)