Split and Replace
Given three strings
inputString, separator and replaceString as inputs. Write a JS program to split the
inputString with the given separator and replace strings in the resultant array with the replaceString whose length is greater than 7.
input:
Javascript-is-amazing
-
programming
output:
programming is amazing
input:
the&lion&king
&
tiger
output:
the lion king
function splitReplace(inputString, separator, replaceString) {
return inputString.split(separator).map(item => item.length > 7 ? replaceString : item).join(' ')
}
Comments
Leave a comment