["Beg", "Life", "I", "To"]) => ["I", "To", "Beg", "Life"]

function sortByLength(array) {
  let sortArr = array.sort(function(a, b) {
    if (a.length > b.length) return 1;
      if (a.length < b.length) return -1;
  })

  return sortArr;
};

sortByLength(["Telescopes", "Glasses", "Eyes", "Monocles"]);

s

function sortByLength (array) {
  return array.sort((a,b) => a.length - b.length);
};

results matching ""

    No results matching ""