jeudi 26 novembre 2020

how does a one line if statment work? return -1, 0 and 1? [duplicate]

return ((a.id > b.id) ? -1 : 1);

What does -1 and 1 mean? I know, that if a is bigger than b it is -1 and otherwise 1. But what does -1 and 1 mean? For which purpose would I use 0?

PS: This return function is to sort an array by id.

Aucun commentaire:

Enregistrer un commentaire