JSFiddle - React, Tailwind, and code Playground
by core972
JavaScript
// 8 12 15 20 36 83 130
const myArray = [15, 36, 20, 12, 8, 20, 83, 130];
console.log("Ordre attendu 8 12 15 20 36 83 130");
console.log(myArray.sort());
console.log(myArray.sort((a,b)=>{
if (a < b) {
console.log("a est plus petit que b", a, b);
return -1;
} else if (a > b) {
console.log("a est plus grand que b", a, b);
return 1;
} else {
console.log("3eme cas a === b", a, b);
return 0;
}
}));