Mutable array methods

Maël Nison nison.mael at gmail.com
Thu Mar 8 09:02:18 PST 2012


Shouldn't native versions be more efficients ?

On 8 March 2012 17:45, David Bruant <bruant.d at gmail.com> wrote:

> Le 08/03/2012 13:02, Maël Nison a écrit :
>
>> Hi,
>>
>> I'm just wondering why there is no mutable function with Javascript
>> arrays.
>>
>> For exemple, if I want to remove every entry matching 42 from an array, I
>> will have to write something like :
>>
>> > var array = [ 0, 1, 42, 3, 4, 5, 42, 42, 42 ];
>> > array = array.filter( function ( x ) { return x === 42; } );
>>
>> Why is it necessary to make a copy ? Why can't we just write something
>> like this ?
>>
>> > var array = [ 0, 1, 42, 3, 4, 5, 42, 42, 42 ];
>> > array.mfilter( function ( x ) { return x === 42; } ); // mutable filter
>>
>> (...)
>>
>>
>> Is there a reason for these missing functions ?
>>
> None besides history.
> It's still possible to add these functions to Array.prototype yourslef,
> though.
>
> David
>



-- 
Maël Nison
Epitech 2014, Paris - Astek
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120308/1a700158/attachment-0001.html>


More information about the es-discuss mailing list