Adding .map() directly to String prototype

2018-05-17 Thread Ben Fletcher
Consider adding the array .map() implementation directly to the String 
prototype.

Here is a possible polyfill:

String.prototype.map = function (fn) {
  return Array.prototype.map
.call(this, fn)
.join('');
}

This replaces the common pattern of splitting, mapping, joining strings for 
processing.
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: es-discuss Digest, Vol 135, Issue 48

2018-05-23 Thread Ben Fletcher
Does the `[...oldArr, ...elementsToPushArr]` pattern take care of that for
you? I've always assumed it's much less performant than your form would be,
but I (naively) suppose the implementation could be optimized like anything
else

On Wed, May 23, 2018 at 8:01 AM  wrote:

> Send es-discuss mailing list submissions to
> es-discuss@mozilla.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://mail.mozilla.org/listinfo/es-discuss
> or, via email, send a message with subject or body 'help' to
> es-discuss-requ...@mozilla.org
>
> You can reach the person managing the list at
> es-discuss-ow...@mozilla.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of es-discuss digest..."
> Today's Topics:
>
>1. Array.prototype.append ? (Jordi Bunster)
>
>
>
> -- Forwarded message --
> From: Jordi Bunster 
> To: "es-discuss@mozilla.org" 
> Cc:
> Bcc:
> Date: Wed, 23 May 2018 02:45:25 +
> Subject: Array.prototype.append ?
> Has anyone ever suggested Array.prototype.append as an
> Array.prototype.push which returns the array itself? It would be
> reduce-friendly, same as Set.prototype.add and Map.prototype.set.
>
> Someone has to have, right? 
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss