In this snippet, inside of the sort method, why do I need to add two parameters? Why can’t I just access the numTeeth property? Would that not suffice to have sort() place the numbers in ascending order?
const speciesArray = [ {speciesName:'shark', numTeeth:50}, {speciesName:'dog', numTeeth:42}, {speciesName:'alligator', numTeeth:80}, {speciesName:'human', numTeeth:32}];
const sortSpeciesByTeeth = (arr) => {
const result = arr.sort((teeth1, teeth2) => teeth1.numTeeth > teeth2.numTeeth);
return result
}
console.log(sortSpeciesByTeeth(speciesArray))