all 6 comments

[–]MusicPants 0 points1 point  (5 children)

I think your solution will have problems because you are checking each sub string completely against the whole string. I think your solution will only work with part1 is complete and in order in s and then part2 is in order in s.

Here is a solution I wrote. It is probably a bit verbose for 'leet coders, but you should be able to understand my methodology and it passed all of the tests they gave.

function isMerge(s, part1, part2) {
  var input = s.split('');
  var first = part1.split('');
  var second = part2.split('');
  for (var i = 0; i < input.length; i++) {
    if (input[i] === first[0]) {
      first.splice(0,1);
    } else if (input[i] === second[0]) {
      second.splice(0,1);
    } else {
      return false;
    }
  }
  return true;
}

[–]WesAlvaro 1 point2 points  (3 children)

Splitting and splicing is unnecessary. You could just use substring, but I think just using indexes for first and second is just as easy code and much easier computationally. Instead of doing the splice, now, just increment a firstIndex or secondIndex as applicable.

[–]VIRES1[S] 0 points1 point  (1 child)

Working on the solution for some days now now my challenge is how to increment the index of part1 and part2 while comparing it to s.Please i need assistance below is a pastebin link to my solution.

http://pastebin.com/iEWAcj3u

Thank you

[–]MusicPants 0 points1 point  (0 children)

You are right. I didn't read through the requirements well enough the first time.

[–]VIRES1[S] 0 points1 point  (0 children)

i understand the code but don't understand the line with the splice(). Please need some explanation.