Hi! I am currently on problem set 17 in the “functional programming” chapter of JavaScript Algorithms & Data Structures, and finally got the solution, however I did the long method and didn’t do a 1 line method like the solution suggested doing. I see the solution is listed as:
function alphabeticalOrder(arr) {
// Add your code below this line
return arr.sort(function(a, b) {
return a === b ? 0 : a < b ? -1 : 1;
});
// Add your code above this line
}
alphabeticalOrder(["a", "d", "c", "a", "z", "g"]);
However, I have no idea what the syntax means in this one line function statement.
Particularly, the “?” and “:”, what do they mean?
Thanks for any help!
**Your browser information:**
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:89.0) Gecko/20100101 Firefox/89.0
Challenge: Sort an Array Alphabetically using the sort Method
Link to the challenge: