collect.js
collect.js copied to clipboard
Method `reduce` with `key/index`
Currently it is not possible to access the Key/Index of the item while using reduce()
$collection->reduce(function ($carry, $value, $key) use ($ratio) {
return $carry + ($value * $ratio[$key]);
});
https://laravel.com/docs/9.x/collections#method-reduce
Hi. Thanks for reporting. Could you please provide an example on Runkit?
https://npm.runkit.com/collect.js
Hi. Thanks for reporting. Could you please provide an example on Runkit?
https://runkit.com/embed/t67a6zx0ng4g
Notice how the Object logs the keys, but the Array does not. I understand that there are no keys on an array, but we should get the indexes instead.
Can you please check my PR, it says it failed but I can't see the error.