Array.prototype.joinWith(iterable)

Michał Wadas michalwadas at gmail.com
Thu Aug 15 10:52:52 UTC 2019


I would rather see Array.zip, it covers this use case.

On Thu, 15 Aug 2019, 10:50 Andrea Giammarchi, <andrea.giammarchi at gmail.com>
wrote:

>
> I wonder if there's any interest in adding another handy Array method as
> joinWith could be:
>
> ```js
> // proposal example
> Array.prototype.joinWith = function (values) {
>   const {length} = this;
>   if (length < 2)
>     return this.join('');
>   const out = [this[0]];
>   const len = values.length;
>   for (let i = 1; i < length; i++) {
>     console.log(i, len);
>     out.push(values[(i - 1) % len], this[i]);
>   }
>   return out.join('');
> };
> ```
>
> The goal is to simplify joining array entries through not the same value,
> example:
>
> ```js
> console.log(['a', 'b', 'c', 'd'].joinWith([1, 2]));
> // a1b2c1d
>
> function tag2str(template, ...values) {
>   return template.joinWith(values);
> }
>
> tag2str`a${1}b${2}c`;
> // "a1b2c"
> ```
>
> Throughts?
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20190815/af8591b5/attachment-0001.html>


More information about the es-discuss mailing list