collect.js icon indicating copy to clipboard operation
collect.js copied to clipboard

Method `reduce` with `key/index`

Open SDIjeremy opened this issue 2 years ago • 3 comments

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

SDIjeremy avatar Jan 16 '23 18:01 SDIjeremy

Hi. Thanks for reporting. Could you please provide an example on Runkit?

https://npm.runkit.com/collect.js

ecrmnn avatar Jan 18 '23 08:01 ecrmnn

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.

jjjrmy avatar Jan 19 '23 20:01 jjjrmy

Can you please check my PR, it says it failed but I can't see the error.

SDIjeremy avatar Jan 21 '23 22:01 SDIjeremy