DEV Community

Discussion on: Daily Challenge #44 - Mexican Wave

Collapse
 
chrisachard profile image
Chris Achard

In my quest for a single line function, I missed the part about skipping the character if it's whitespace... so here's that tacked on too (though I added the filter to the end in order to keep the whole thing to one line) :)

const wave = str => [...str].map((c, i) => `${str.slice(0, i)}${c.toUpperCase()}${str.slice(i +  1, str.length)}`).filter(s => /[A-Z]/.test(s))
Collapse
 
jeddevs profile image
Theo

Always amazes me when people get it into one line. 👍

Thread Thread
 
chrisachard profile image
Chris Achard

map, filter, and reduce are your friend! Whenever I'm dealing with translating one string, array, or object into another one, there's probably a way to do it by just chaining those three methods together.

Thread Thread
 
jeddevs profile image
Theo

Nice, I'm a python man myself and will be sure to check it out! 👍
(I believe map,filter and reduce are available in python as well....)

Thread Thread
 
moopet profile image
Ben Sinclair

Minimising your javascript will get everything onto one line. I'm not sure about why you'd want to do that when showing your code to anyone though.