Answer to Question #171200 in HTML/JavaScript Web Application for manikanta

Question #171200

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

  • You can use the string method split()
  • You can use the array method map()

Input

  • The first line of input contains a string inputString
  • The second line of input contains a string separator
  • The third line of input contains a string replaceString

Output

  • The output should be a single line containing the strings separated by a space

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




1
Expert's answer
2021-03-12T23:41:50-0500
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);

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS