freeCodeCamp Challenge Guide: Filter Arrays with Filter

freeCodeCamp Challenge Guide: Filter Arrays with Filter
0

#1

Filter is a useful method that can filter out values that don’t match a certain criteria.

var array = [1,2,3,4,5,6,7,8,9,10];
  // Only change code below this line.
array = array.filter(function(val) {
  return val < 5;
});

What is val parameter how it is cakled or passed?
#2

Hi The only problem is that we need to correct conditions or text. Watch it out here


#3

Hey fellow campers,here is how I did it:

var oldArray = [1,2,3,4,5,6,7,8,9,10];

// Only change code below this line.

var newArray = oldArray.filter(function(val) {
return val < 6;
});


#4

the condition " return val <= 5" isn’t working and it’s weird.


#5

and the condition " return val < 6" also not working…


#6

Hello @garnicha.The instruction says that we use "filter" to create/return a new array with all the values from oldArray which are less than 6.

So, simply put,our new array should not have a number which is 6 or more than 6.Like this:

var oldArray = [1,2,3,4,5,6,7,8,9,10];

// Only change code below this line.

var newArray = oldArray.filter(function(val){
return val < 6;

});