I have asked this question before (the first link to my question) but couldn\'t get the complete solution for the question. Write an algorithm to check if a given string, s, can
Here is a non-recursive approach.
function checkIt (str, str1, str2){
if(str.length !== str1.length + str2.length){
return false;
}
var str1_index = -1
var str2_index = -1;
var curr_index1, curr_index2;
for(var i=0; i str1_index){
str1_index = curr_index1;
}
else if(curr_index1 !== -1 && curr_index1 < str1_index) {
return false;
}
if(curr_index2 > str2_index){
str2_index = curr_index2;
}
else if(curr_index2 !== -1 && curr_index2 < str2_index) {
return false;
}
}
return true;
}
console.log(checkIt('codewars', 'cdw', 'oears')); // true
console.log(checkIt('codewars', 'cdw', 'ears')); // false
console.log(checkIt('codewars', 'cwd', 'oears')); // false
console.log(checkIt('codewars', 'cdw', 'oeasr')); // false