JavaScript 30 — Day 4 — Array Cardio 1

  • map
  • sort
  • filter
  • reduce
  • One of the exercises required a conversion from a NodeList to an Array. While I know how to use the ES6 spread operator to make the conversion, the older Array.from() method also works in this case. It is perhaps more syntactically logical but I’m a fan of the former since it’s a little shorter and provides some other flexibility.
  • I had never really thought to throw an object as a parameter in a .reduce() for whatever reason. The method just takes in a parameter so it’s no different than what you can pass to a regular function, it had just never occurred to me.
newArray.reduce((a,b) => a-b > 0 ? 1: -1)
newArray.reduce((a,b) => a-b)

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Javascript Asynchronous programming

Prompt Users to Add Token to MetaMask

Learn React the fast way

React-Router

What’s all this fuss about data-binding?

How To Implementation Socket.io On Strapi

Getting Started with Three.js

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Steven Chen

Steven Chen

More from Medium

JavaScript and jQuery

JavaScript 30 — Day 6 — Type Ahead

How to keep bootstrap 4 navbar dropdown menu open on mouseleave?

Objects and its internal representation in Javascript