I got an issue trying to reduce with _.filter
method a list of (valid) ids. The aim is to create a new id according to the last value of the number given at the end of each string (string-string-[lastNumber+1]).
Because I do not want to receive an invalid id. I just tried to filter these ids using the regexp
inside of _.filter
method.
However, the result looks very weir. Despite the fact that of these strings passed the online test of regexp validation.
REPL testing
var data = [
'offstreetparking-estepona-1',
'offstreetparking-estepona-2',
'offstreetparking-estepona-3',
'offstreetparking-estepona-04', // Should nor be included (not 04)
'offstreetparking-estepona-4',
'offstreetparking-estepona-5'
]
var patt = /([A-Za-z]+)-([A-Za-z]+)-([1-9]+)/g;
_.filter(data, d => patt.test(d));
// Result from lodash => [
"offstreetparking-estepona-1",
"offstreetparking-estepona-3",
"offstreetparking-estepona-4"
]
// Missing => 2 and 5 ids!
I don't know why some of valid ids are not passing the test inside of _.filter
function and are returned as element of the array.
All of them were tested independently and works fine :(
The wrong behavior that lodash returned just the odds values...
Any other solutions are welcome, but I want to know why lodash is not working properly at this point.
Many thanks!