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

Single item / array tip doesn't account for undefined values #42

Closed
boneskull opened this issue Jan 8, 2016 · 8 comments
Closed

Single item / array tip doesn't account for undefined values #42

boneskull opened this issue Jan 8, 2016 · 8 comments

Comments

@boneskull
Copy link
Contributor

Maybe better to

value = [].concat(value || [])

@boneskull
Copy link
Contributor Author

Otherwise you get [undefined]

@Amberlamps
Copy link

Also, usually you do not execute functions to log values to the console, but rather to process data and return values. If I pass a string to a function, I expect a string as return value, or at least not an array. It usually messes up the workflow in which the function is executed. I liked to add something like:

return typeof arguments[0] === 'string' ? elements[0] : elements;

@BlaM
Copy link

BlaM commented Jan 8, 2016

@Amberlamps: About the return value: I prefer to get the same type of return value each time I call a function - not a string once and an array the next time. Seems to be personal preference, but I'd say most functions always have a constant return type.

@Amberlamps
Copy link

@BlaM: I agree. But when I use a third party library that converts strings to upper case, I find it weird to get an array when passing a string.

console.log(require('third-party-lib').upperCase("javascript"));
// => ["JAVASCRIPT"]

@BlaM
Copy link

BlaM commented Jan 8, 2016

@Amberlamps: Usually you wouldn't rely on a third party lib to uppercase strings - you would use String.toUpperCase() 😋. But in the end it all comes down to the definition of the function. There is no right or wrong here - and returning uppercase is just an example.

@loverajoel
Copy link
Owner

Hey can we close this?

@boneskull
Copy link
Contributor Author

My original comment was not addressed. You guys went off on a tangent. 😄

@zenopopovici
Copy link
Collaborator

@boneskull if you have any improvements can you submit a new PR? Or let us know if this can be closed.

zenopopovici added a commit that referenced this issue Mar 1, 2016
Modify tip to avoid throwing; closes #42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants