Created
April 2, 2021 00:06
-
-
Save brito/df7d8c831858352f3182c195b5bceffc to your computer and use it in GitHub Desktop.
Transform a string using multiple regex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Transform a string using multiple regex | |
@customfunction | |
*/ | |
function replaces(operators,operands) { | |
return operators[0].map ? | |
operators.reduce((a,b) => replaces(b,a), operands) | |
: operands.replace(new RegExp(operators[0]), operators[1]) | |
} | |
function __TESTS(){ __TEST_0_replaces(), __TEST_1_replaces()} | |
function __TEST_0_replaces(){ Logger.log(replaces(['hello', 'tests'],'hello world')) } | |
function __TEST_1_replaces(){ Logger.log(replaces([['hello', 'tests'],['world','pass']],'hello world')) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment