Closed tamakiii closed 8 years ago
rel: https://github.com/Anahkiasen/underscore-php/issues/33
I would like to implement Types\Arrays::indexBy() that is implemented in underscore.js. It's _.indexBy() work like this:
Types\Arrays::indexBy()
underscore.js
_.indexBy()
> var stooges = [{name: 'moe', age: 40}, {name: 'larry', age: 50}, {name: 'curly', age: 60}]; undefined > u.indexBy(stooges, 'age'); { '40': { name: 'moe', age: 40 }, '50': { name: 'larry', age: 50 }, '60': { name: 'curly', age: 60 } } > > u.indexBy(stooges, 'hoge'); { undefined: { name: 'curly', age: 60 } }
In case of non-existing key is specified, underscore.js's _.indexBy() return last element with key undefined (this might not be intentionally).
undefined
But it's better not to include in result in PHP. So,
$ php -r 'print_r(Arrays::indexOf(..., "hoge");' Array ( )
hmmm...
@Anahkiasen Please merge this.
@Anahkiasen Thank you! :)
rel: https://github.com/Anahkiasen/underscore-php/issues/33
I would like to implement
Types\Arrays::indexBy()
that is implemented inunderscore.js
. It's_.indexBy()
work like this:In case of non-existing key is specified,
underscore.js
's_.indexBy()
return last element with keyundefined
(this might not be intentionally).But it's better not to include in result in PHP. So,