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))




Bushan Sirgur

Hey guys, I am Bushan Sirgur from Banglore, India. Currently, I am working as an Associate project in an IT company.

Leave a Reply