Introduction
For this example, let's take the string Hello, World!
and the array [3, 2, 3]
. To find the substring chain, we go through the following process:
The first number of the array is 3
, so we get the substring [0 - 3]
, which is Hel
. After that, we remove the first 3
characters from the initial string, which leaves us with lo, World!
.
The second number of the array is 2
, so we get the substring [0 - 2]
from our new string, which gives us lo
. The leftover string becomes , World!
.
The last number is a 3
, which gives us , W
. The substring chain is all of the substrings combined, which gives us:
['Hel', 'lo', ', W']
For a more visual example:
[3, 2, 3], 'Hello, World!'
3 -> Hel
2 -> lo
3 -> , W
The task
Given a non-empty string and a non-empty array only consisting of positive integers (> 0
), output the substring chain. You may assume that the sum of all integers in the array does not exceed the length of the string.
You can also assume that the strings will never contain any newlines.
Test cases
Input: abcdefghijk, [2, 1, 3]
Output: ['ab', 'c', 'def']
Input: Code Golf, [4, 1]
Output: ['Code', ' ']
Input: Ayyy, [3]
Output: ['Ayy']
Input: lexicographically, [2, 2, 2, 7, 4]
Output: ['le', 'xi', 'co', 'graphic', 'ally']
This is code-golf, so the submission with the smallest number of bytes wins!