Uber Interview Question

Find and replace a set of substrings within a string. (javascript)

Interview Answer

Anonymous

Apr 29, 2018

function signature for replace is str.replace(regexp|substr, newSubstr|function), so we can do str.replace(/strToBeReplaced/g, targetString) to get the solution. Our regex might need to escape some characters if strToBeReplaced contains special characters like wildcards