Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed == to === and formatted to jslint standards. #61

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

changed == to === and formatted to jslint standards. #61

wants to merge 3 commits into from

Conversation

jlaustill
Copy link

I'm VERY new to git and github, I've been developing in C# and using svn and mercurial for a very long time. So I decided to pick a project that I could just work on getting more familiar with and try to help with small improvements. If this isn't how you like to work, or if you'd rather I go learn somewhere else that won't hurt my feelings at all :)

All I did here was pick the smallest function I could find in your code and format it to pass a jslint test, then made sure all of your 100 specs still ran successfully. Not a huge improvement :)

@crissdev
Copy link

I would leave the check for null as it was before just to prevent the function from failing on undefined value.

@jlaustill
Copy link
Author

That is a valid concern, but I assumed the null value was the direct intention. If it's not, I would ask if it should also be checking for Nan and false? The == comparison won't detect those.

Just checking for a truthy match would replace a numerical 0 with an empty string if I'm not mistaken, and since the next statement checks for numerals and converts them to strings, I assume that is an unwanted behavior as well.

I would rather see if string === null || string === undefined myself if that is the intention.

@jlaustill
Copy link
Author

Ok, I went through this as thoroughly as I could and created specs for this function. Which unsurprisingly brought up more questions :) The regex for the replacement after casting to string is pretty straight forward, but I couldn't for the life of me think of what object would be cast to string that would contain a non breaking space that needed trimmed. If you can give me an example I would gladly add the test for it as this one kind of has me stumped.

Also, currently this function will return the string "NaN" if you pass in NaN, and that seems to be the case with == null or === null. Is this expected behavior? I would expect maybe a trim function to throw on that as it would most likely indicate a serious issue elsewhere in the code, but maybe that isn't the case and it should just return an empty string? I'm curious on your thoughts.

In any rate, tweak these tests/specs and give me the example from above and I will gladly make this function jslint quality that satisfies all tests. I love puzzles like this.

@mbest
Copy link
Owner

mbest commented Jan 13, 2016

string === null || string === undefined is the intention.

@jlaustill
Copy link
Author

Updated to reflect as such :) All tests passing.

@mbest
Copy link
Owner

mbest commented Jan 13, 2016

undefined and null are the only values for which you can't call toString(). They also usually have a meaning of "unset", which is generally displayed as blank.

@jlaustill
Copy link
Author

Awesome, that's exactly why I'm doing this, to learn stuff like that. I'll have to research unset a bit.

@mbest
Copy link
Owner

mbest commented Jan 13, 2016

I'm speaking mostly of convention within JavaScript apps, especially with Knockout. Even a variable that will generally hold a string may be declared without being initialized and so have a value of undefined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants