diff options
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/findAllIndicesOf.ts | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/lib/findAllIndicesOf.ts b/src/lib/findAllIndicesOf.ts new file mode 100644 index 0000000..8f1a100 --- /dev/null +++ b/src/lib/findAllIndicesOf.ts @@ -0,0 +1,14 @@ +export default function (searchFor: string, searchIn: string): number[] { + const indices: number[] = []; + + let index = -1; + while (index !== searchIn.length - 1) { + index = searchIn.slice(index + 1).indexOf(searchFor) + index + 1; + if (index === -1) { + break; + } + indices.push(index); + } + + return indices; +} |
