[LRUG] Recursion diversion

Andrew Stewart boss at airbladesoftware.com
Fri Oct 25 06:21:11 PDT 2013


Hello El Rug,

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.

a: 'hello world'
b: 'e'
result: [ [1] ]

a: 'hello world'
b: 'l'
result: [ [2,3,9] ]

a: 'hello world'
b: 'el'
result: [ [1,2], [1,3], [1,9] ]

a: 'hello world'
b: 'lo'
result: [ [2,4], [2,7], [3,4], [3,7] ]

a: 'hello world'
b: 'lod'
result: [ [2,4,10], [2,7,10], [3,4,10], [3,7,10] ]

Hope that makes sense ;)

I've been trying this for ages, with iteration and recursion, and I keep getting close...but not quite there.

Any takers?

Cheers,
Andy Stewart


More information about the Chat mailing list