I have a sequence of replace methods, including regular expressions. They are all put together like this:
motivation = motivation.replace('death','life').replace('sad','happy').replace(/fu+ck/gi,'yay!').replace('darkness','light');
Is there a way to organize this to be more readable? Not having to repeat “replace” all the time would be a good start. I also have access to the Mootools library.
Here’s the simplest thing I can think of: clever indentation.
Another option is just to use something like
Array.each(I think that’s in Mootools):This only really makes sense for very long lists of replacements.