Code
function SortByID(x,y) {
return x.id - y.id;
}
function SortByName(x,y) {
return ((x.Name == y.Name) ? 0 : ((x.Name > y.Name)? 1: -1));
}
Problem Description
I am new to Javascript and I am learning how to make a sorting algorithm. I have a few questions regarding the two functions above.
1.Can you please explain the line of code below to me in words?
return ((x.Name == y.Name) ? 0 : ((x.Name > y.Name)? 1: -1));
2.What does the question mark in the above code mean?
3.what doest the "? 1: -1" and "? 0 :" means?
Many Thanks!