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.
Quick Tip
Sample Input 1
JavaScript-is-amazing
-
Programming
Sample Output 1
Programming is amazing
Sample Input 2
The&Lion&King
&
Tiger
Sample Output 2
The Lion King
let inputString = prompt('Enter the string: ');
let seperator = prompt('Enter a seperator');
let replaceString = prompt('Enter a string for a replace');
let array = inputString.split(seperator);
for (let i = 0; i < array.length; i++) {
if (array[i].length > 7) {
array[i] = replaceString;
}
}
console.log(array);
Comments
Leave a comment