Noob question. So, I am sorting an array of numbers in ascending order, but I don't understand why this works.
const sortYears = arr => {
arr = (a, b) => {return a - b;}
}
const years = [1970, 1999, 1951, 1982, 1963, 2011, 2018, 1922];
console.log(years.sort(sortYears()));
What does a - b
actually achieve? Is it not just returning another number? How is it suddenly able to sort these numbers?