dimanche 6 novembre 2022

Please explain what is happening in below line of code [duplicate]

let arr = [1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8];
arr.sort(() => Math.random() > 0.5 ? 1 : -1);

Please explain what is happening by the above lines of code, why we are returning 1 or -1 and what is the use of returning them.




Aucun commentaire:

Enregistrer un commentaire