convert a function to ES6 [closed]

0

my function is:

function filter_list(arrays) {
 return  arrays.filter(function(current){
  if(typeof current==="number"){
    return current;
  }
 });
}

console.log(filter_list([1,2,'a','b'])); 

I wanted to convert it like that

function filter_list(arrays) {
  return arrays.filter(arrays.filter(current => typeof current === "number");
  }

  console.log(filter_list([1, 2, 'a', 'b']));

but it goes wrong !!!

    
asked by hubman 11.01.2018 в 17:51
source

2 answers

1

You're calling arrays.filter 2 times!
The first declaration of% co_of% over.

function filter_list(arrays) {
  return arrays.filter(current => typeof current === 'number');
}

console.log(filter_list([1, 2, 'a', 'b']));
    
answered by 11.01.2018 в 17:57
1

Syntactically you are missing a parenthesis and functionally it is not necessary to use the filter method 2 times.

I leave you as I would be in ES6:

var filterList = arr => arr.filter(cur => typeof cur === 'number');

console.log(filterList([1,2,'a','b'])); 
    
answered by 11.01.2018 в 19:02