What I would like to create is a filter which will pull the numbers out of text that is put in a text box. For example:
User types: The cat went to 4 stores and bought 3 bags of cat litter for 1 dollar.
Result would be: [4, 3, 1]
The filter will see because of a previous filter ['the', 'cat', 'went', 'to', '4' ...]
So what I tried to create was a for loop that would go through the array and check each item to see if it is in fact a number. However, the for loop breaks the app when it isn't commented out. Any help is appreciated.
filter('showNum', function() {
// this filter is not complete but it will return only numbers from an array
return function isNumeric(title){
var numbers, i, len, numberToAdd;
numbers = [];
len = title.length;
// for(i=0; i<len; i+=1){
// numberToAdd = title[i];
// if(!isNAN(numberToAdd)===False); {numbers.push(numberToAdd);}
return numbers;
};
})

"The cat went to 4 stores and bought 3 bags of cat litter for 1 dollar.".match(/\b\d+\b/g)returns4,3,1