Array.prototype.smoosh and smooshMap polyfill for all!
$ npm install --save array-smoosh
Then import 'array-smoosh'
once, anywhere early inside your application, and you're good to go.
- Works on older browsers with no own map implementation
- No conditional monkey patching, so the web will never break your website 😱
Smooshes the Array. If no level is given, the Array gets smooshed recursively.
[1, [2, [3]]].smoosh(1); // => [1, 2, [3]]
['I', ['love', ['funny', ['method', ['names']]]]]
.smoosh()
.join(' '); // => 'I love funny method names'
Smooshes the Array recursively and applies the given projection function to each element.
[1, [2, [3]]].smooshMap(n => n * 3); // => [3, 6, 9]
['smoosh', ['all', ['the', ['things']]]]
.smooshMap(s => s.toUpperCase() + '!')
.join(' ') // => 'SMOOSH! ALL! THE! THINGS!'
MIT © Nicolai Süper (nico@k40s.net)