On Friday, January 29, 2016, Rick Waldron <waldron.r...@gmail.com> wrote:

>
>
> On Fri, Jan 29, 2016 at 6:08 PM Kaustubh Karkare <
> kaustubh.kark...@gmail.com
> <javascript:_e(%7B%7D,'cvml','kaustubh.kark...@gmail.com');>> wrote:
>
>> I have recently come to feel the need for Object.map, which is like
>> Array.map,
>> except that it receive keys instead of indices.
>>
>> Object.prototype.map = function(mapFn, context) {
>>   return Object.keys(this)
>>     .reduce(function(result, key) {
>>       result[key] = mapFn.call(context, this[key], key, this);
>>       return result;
>>     }, {});
>> };
>>
>> Without this, I frequently do the exact same thing as the above manually,
>> which leads to unnecessary code duplication.
>>
>> Given that, it might make sense to match other methods from
>> Array.prototype
>>
>> Object.map
>> Object.filter
>> Object.every
>> Object.some
>> Object.reduce
>> Object.find
>> Object.findKey // like Array.findIndex
>>
>
>
> Are these necessary given the introduction of Object.values() and
> Object.entries()? https://github.com/tc39/proposal-object-values-entries
>
>
I think what Kaustubh is proposing is that the result is a transformed
object/map, not an array. See the reduce method in his implementation.

Dmitry



> Rick
>
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to