Given an “out” string length 4, such as “<<>>”, and a word, return a new string where the word is in the middle of the out string, e.g. “<>”





Following are the test cases

Test cases Result Status
makeOutWord(<<>>,Yay) <<Yay>> OK
makeOutWord([[]],Word) [[Word]] OK
makeOutWord([((JAVA))] ((JAVA)) OK

Java solution


package test;

public class Program17 {
	public static void main(String[] args) {
		Program17.makeOutWord("<<>>", "Yay");
		Program17.makeOutWord("<<>>", "WooHoo");
		Program17.makeOutWord("[[]]", "word");
	}
	public static String makeOutWord(String out, String word) {
		return out.substring(0, 2) + word + out.substring(2,4);
	}
}

Javascript solution


const makeOutWord = (out, word) => {
    return out.substr(0, 2) + word + out.substr(2, 4);
}

console.log(makeOutWord("<<>>", "Yay")); //<>
console.log(makeOutWord("<<>>", "WooHoo")); //[[Word]]
console.log(makeOutWord("[[]]", "word")); //((JAVA))




About the author

Bushan Sirgur

Well, I am Bushan Sirgur from Banglore, India. Currently, I am working as a Software Developer in a Service Base Company. I am interested in JAVA/J2EE, Angular 2, JavaScript, jQuery, MongoDB.

View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *