Answer the question
In order to leave comments, you need to log in
How to search and replace sequences of elements in arrays?
Most programming languages have tools for finding and replacing sequences of characters in strings. But how to do the same, but with elements in arrays?
For example, there is an array of hashes:
[
{ type: 1, content: "lorem" },
{ type: 2, content: "ipsum" },
{ type: 3, content: "dolor" },
{ type: 4, content: "sit" },
{ type: 2, content: "amet" },
{ type: 1, content: "consectetur" },
{ type: 2, content: "adipisicing" },
{ type: 3, content: "elit" },
]
[
{ type: 1, content: "loremipsumdolor" },
{ type: 4, content: "sit" },
{ type: 2, content: "amet" },
{ type: 1, content: "consecteturadipisicingelit" },
]
[
{ type: 1, content: "loremipsumdolor" },
{ type: 5, content: "woohoo" },
{ type: 1, content: "consecteturadipisicingelit" },
]
Answer the question
In order to leave comments, you need to log in
First, the Aho-Korasik algorithm to find the desired sequences. Then perform actions.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question