Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * fn: https://pastebin.com/WzcVWLU1
- * This function takes two parameters:
- *
- * str - The original string in which the replacements will be performed.
- * replacements - An array of tuples, where each tuple contains the search
- * text and its corresponding replacement text.
- * The function iterates over each tuple in the replacements array.
- * For each tuple, it calls the replace method on the result string,
- * replacing all occurrences of the search text with the replacement
- * text using a regular expression with the 'g' flag for global search.
- *
- * The resulting modified string is returned from the function.
- *
- **/
- const originalString = 'Hello, world! Hello, universe!';
- const replacements: [string, string][] = [
- ['Hello', 'Hi'],
- ['world', 'earth']
- ];
- const modifiedString = replaceMultipleValues(originalString, replacements);
- console.log(modifiedString); // Hi, earth! Hi, universe!
- /**
- * Output: Hi, earth! Hi, universe!
- *
- * In this example, the original string 'Hello, world! Hello, universe!'
- * is modified by replacing "Hello" with "Hi" and "world" with "earth",
- * resulting in the modified string 'Hi, earth! Hi, universe!'.
- **/
Advertisement
Add Comment
Please, Sign In to add comment