Problem:
Given a string, if the string "del" appears starting at index 1, return a string where that "del" has been deleted. Otherwise, return the string unchanged.
delDel("adelbc") → "abc"
delDel("adelHello") → "aHello"
delDel("adedbc") → "adedbc"
Solution:
public String delDel(String str) { if (str.startsWith("del", 1)) return str.charAt(0) + str.substring(4, str.length()); else return str; }
function delDel(str){
ReplyDeletelet a = str.substr(1,3);
if (a == 'del'){
return str.replace('del', '');
} else return str;
}
public String delDel(String str) {
ReplyDeletereturn (str.startsWith("del",1))?str.replace("del", ""):str;
}