Is there a way to arrange these arrays in descending order of the number of items they contain? I believe the logic is correct, but I might be missing some essential methods. The current output is empty.
//Declare Variables
var TN = ['Chattanooga', 'Nashville', 'Memphis'],
FL = ['Tampa', 'Miami', 'Orlando', 'Clearwater'],
GA = ['Atlanta', 'Marietta'];
//Create a function to sort arrays from most to least items
function sortStates(a, b){
return a - b;
}
//Create an object to store the total items in each array
var stateTotal = {
totalTN: TN.length,
totalFL: FL.length,
totalGA: GA.length
};
//Sort states in descending order based on the number of items
stateTotal.sort(sortStates);
console.log(stateTotal);
Expected Output:
totalFL: 4, totalTN: 3, totalGA: 2