How would I write a function in javascript that would return the number of letters shared between two strings (in order).
eg: if the two strings are read and bread, it should return 4.
I’m thinking of using loops somehow but it seems it would be very convoluted with a lot of iterations, and I’m not sure where to begin.
Is there a way to achieve this using regex? Possibly, get the substring that matches? The length can then be derived from substring.length
The algorithm for the Longest Common Substring problem is kind of tricky. I don’t think there is an easy way do do the equivalent with regex.