Skip to content

Conversation

@maxknee
Copy link

@maxknee maxknee commented Dec 17, 2016

No description provided.

@nitishdayal
Copy link

The curly brackets aren't always needed for arrow function syntax, and in this case they are unwanted; by defining the body of the function without curly brackets we are returning the value from the ternary operator without having to use the return keyword. The .sort() method accepts a function as an argument that should allow it to compare values in an iterable object, two at a time, and should return a negative, positive, or 0 numerical value. Depending on the value returned, .sort() places the items where they need to be.

If you place the curly brackets around the ternary operator/function body, the code will still work because .sort() is smart enough to figure it out, but it's not really what .sort() is expecting. You could place a return before the ternary operator, but that's already accomplished by simply excluding the curly brackets in the first place.

Documentation on Arrow Functions

Documentation on Array.prototype.sort()

@wesbos
Copy link
Owner

wesbos commented Dec 20, 2016

Yep! THanks @nitishdayal

@wesbos wesbos closed this Dec 20, 2016
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