examinedliving
5/1/2017 - 3:22 AM

Merged String Problem for Codewars.com

Merged String Problem for Codewars.com


// working on Codewars Merged String Checker Kata
// fails with Test.expect(isMerge('Bananas from Bahamas','Bananas from am','Bahas'));
// this is a work in progress, and I'm bugged by why it is not working.
// https://www.codewars.com/kata/54c9fcad28ec4c6e680011aa/train/javascript

function isMerge(s, part1, part2) {
 var str='';
var part3=[];
 if(part1.length+part2.length!==s.length){
 return false;
 }
 for(var i=0,j=0,k=0;i<s.length;i++){
   
   if(s[i]===part1[j]){
  str+=s[i];
      j++;
 } else if (s[i]===part2[k]) {
   str+=s[i];
   k++;
 }
 console.log('str is:"'+str +'" & j is:='+j+' & k is:='+ k);

 }
window.answer=str;
if(str===s){
 return true;
}
return false;
}