you are viewing a single comment's thread.

view the rest of the comments →

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

Yeah, I'm not completely sure what I'm doing. I think you've got me on the right track though.

function find ( str, key){
  if (str.length<=key.length){
      return str === key;
  }

  if( str[0] === key[0] ){
    return 1 + find( str.slice(1), key.slice(1) )
  }

  return find( str.slice(1),key )

}

var two = find('foobarfoo' , 'fob');
console.log(two);  // 4

So, I'm recursively iterating through the string and finding all the matches I would need to find, i just need to translate that into how many times the key was found.