The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Refactoring: Array.prototype by example [filter, some, forEach]

Refactoring: Array.prototype by example [filter, some, forEach]

5:42
Refactoring is a great opportunity to learn and we have an existing Javascript function that is *lengthy, hard to understand, and overcomplicated*. We'll take a look at putting some of **Javascript's built in Array.prototype methods** to use to help us clean this up and learn by example through refactoring. By taking a few minutes to refactor this existing code, we can get a glimpse at how we can harness the power of the Array and lean on some built in Array functions available to us in Javascript's core without any added utility libraries. In this lesson we touch on just a few of the [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) methods: - [Array.prototype.forEach](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach) - [Array.prototype.filter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) - [Array.prototype.some](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some).
Watch this lesson now
Avatar
egghead.io

Refactoring is a great opportunity to learn and we have an existing Javascript function that is lengthy, hard to understand, and overcomplicated. We'll take a look at putting some of Javascript's built in Array.prototype methods to use to help us clean this up and learn by example through refactoring.

By taking a few minutes to refactor this existing code, we can get a glimpse at how we can harness the power of the Array and lean on some built in Array functions available to us in Javascript's core without any added utility libraries.

In this lesson we touch on just a few of the Array methods:

Avatar
Richard

Much more elegant code I admit but if efficiency is a concern... well, seeing the test executions go up from 0.3 to 0.9 concerns me a little.

Avatar
Ihor

Richard, are you talking about that line where console.log(Math.random()) is ? :)

In reply to Richard
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?