Wednesday, February 26, 2014

Filtering arrays in JavaScript without Underscore.js!

Twelve, one hundred thirty, and forty-four end up in the variable in the blob of code below (which comes from here).

function isBigEnough(element) {
   return element >= 10;
}
var filtered = [12, 5, 8, 130, 44].filter(isBigEnough);

 
 

This would have been a cleaner way to approach this challenge. :(

No comments:

Post a Comment