logo

List Filtering

In this kata you will create a function that takes a list of non-negative integers and strings and returns a new list with the strings filtered out.


My code:

function filter_list(l) {
                        let arrayInt = [];
                        for (let i = 0; i < l.length; i++) {
                          if (typeof l[i] === 'number') {
                            arrayInt.push(l[i]);
                          }
                        }
                        return arrayInt;
                      }                      
                    


And that's the best solution among all users:

function filter_list(l) {
                        return l.filter(function(v) {return typeof v == 'number'})
                      }
                    

New things I learned today: