I have a problem that wants me to take an array of words, and return them in an array from smallest to largest word. This has to be done in a function. I have a simple form of it that is returning the results I desire:
//arr = ["Beg", "Life", "I", "To"]
//arr.sort(function(a, b){
// return a.length - b.length;
//});
But I need to put it into a function. Here is what I have thus far with that part:
function sortByLength (array) {
array.sort(function(a, b){
return a.length - b.length;
});
}
sortByLength(["Telescopes", "Glasses", "Eyes", "Monocles"]);
I am not looking for the answer. Just some advice as to what I am doing wrong. Thanks for your help!