underscore-php icon indicating copy to clipboard operation
underscore-php copied to clipboard

Array::filter doesn't conform to spec

Open Odalrick opened this issue 10 years ago • 1 comments

According to the documentation:

Arrays::filter(array(1, 2, 3), function($value) {
    return $value % 2 != 0; // Returns array(1, 3)
});

However the actual return value is array ( 0 => 1, 2 => 3, ).

This is obviously because it delegates to array_filter which is documented to leave keys intact.

Odalrick avatar Nov 10 '15 09:11 Odalrick

After reading the documentation and tests, it looks like this is intentional. Possibly this should be made explicit in the documentation.

Odalrick avatar Nov 10 '15 15:11 Odalrick