<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Oct 25, 2013 at 3:21 PM, Andrew Stewart <span dir="ltr"><<a href="mailto:boss@airbladesoftware.com" target="_blank">boss@airbladesoftware.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello El Rug,<br>
<br>
Given two strings a and b, I would like to find all the occasions where the letters of b appear in the same order in a.  The result should be an array of arrays where each inner array contains the indices of b's matches in a.<br>

<br>
a: 'hello world'<br>
b: 'e'<br>
result: [ [1] ]<br>
<br>
a: 'hello world'<br>
b: 'l'<br>
result: [ [2,3,9] ]<br>
<br>
a: 'hello world'<br>
b: 'el'<br>
result: [ [1,2], [1,3], [1,9] ]<br>
<br>
a: 'hello world'<br>
b: 'lo'<br>
result: [ [2,4], [2,7], [3,4], [3,7] ]<br>
<br>
a: 'hello world'<br>
b: 'lod'<br>
result: [ [2,4,10], [2,7,10], [3,4,10], [3,7,10] ]<br>
<br>
Hope that makes sense ;)<br>
<br>
I've been trying this for ages, with iteration and recursion, and I keep getting close...but not quite there.<br>
<br>
Any takers?<br>
<br></blockquote><div><br></div><div>I implemented a (quite long) implementation with iteration. Seems to work.<br><br>I did change example 2 to result in:<br><br>  [ [2], [3], [9] ]<br><br></div><div>that seemed more logical to me (there are 3 results, each of length 1).<br>
<br>  <a href="https://gist.github.com/knaveofdiamonds/7155189#comment-936642">https://gist.github.com/knaveofdiamonds/7155189#comment-936642</a><br><br></div><div>Had fun doing this :-)<br><br></div><div>Peter<br></div></div>
</div></div>