On Thu, May 17, 2018 at 11:16 AM, Ben Fletcher <bfle...@gmail.com> wrote:

> Consider adding the array .map() implementation directly to the String 
> prototype.

There is a big difference between mapping over an array and mapping
over a string.  Arrays can hold *anything*.  Strings hold only
characters.  So for a function that takes something of type A and
returns something of type B, `map`ping it over an array takes an array
of As and returns an array of Bs.

```js
['a', 'b', 'c'].map(c => c.charCodeAt(0)) //=> [97, 98, 99]
```
But since a String only holds characters, we can't make it properly
hold the results of `c => c.charCodeAt(0)`:


```js
'abc'.map(c => c.charCodeAt(0)) //=> "979899"
```

`reduce` would be a bit different, as it can accumulate to any type.

I think `map` would be a bad idea here.


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

Reply via email to