Javascript – Why did I take so long?

For years I have been circling around web development. Making websites in HTML, learning how to put together modular sections with PHP and styling it out with CSS. I even delved into mysql and worked out how to access data. What I didn’t do was spend any time with javascript. I’ve know idea why!

I’ve really enjoyed the Codecademy full stack engineer course so far. It incorporated the free javascript course they have on their website but expands on that chapter with extra bits at the end of each section. Little challenges that made me work a bit hard for the green tick.

I’m currently I’m having fun with .sort()

function sortYears(arr, direction) {
  switch (direction) {
    case true:
      return arr.sort((a,b) => a < b) // descending;
    case false:
      return arr.sort((b,a) => a < b) // ascending;
  };
};


const years = [1970, 1999, 1951, 1982, 1963, 2011, 2018, 1922]

console.log(sortYears(years, true))
// Should print [ 2018, 2011, 1999, 1982, 1970, 1963, 1951, 1922 ]


Posted

in

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.