29
1
Given an input of a list of slices of a string, output the original string.
Each slice will be given as a list of length 2, containing the start position of the slice (an integer ≥0) and the slice itself. If your language does not support arrays of arbitrary types, you may also take this as a struct or similar, or simply a string consisting of the number, a space, and then the slice.
The order of the two elements of each slice is up to you. Furthermore, if you choose to use the representation of slices as a length-2 array, you may take input as either a 2-dimensional array or a single flat array. Finally, the integer representing position may be either zero-indexed or one-indexed (all the examples here are zero-indexed).
The input will always be sufficient to determine the entire string up to the highest position given. That is, there will be no "holes" or "gaps." Therefore, the output must not contain any extra trailing or leading characters (other than the typical optional trailing newline). The input will always be consistent, and no slices will conflict with each other.
Since this is code-golf, the shortest code in bytes will win.
Test cases:
In Out
-----------------------------------------------------------
[[2, "CG"], [0, "PP"], [1, "PC"]] | PPCG
[[0, "foobarbaz"]] | foobarbaz
[[0, "foobar"], [6, "baz"]] | foobarbaz
[[2, "ob"], [5, "rba"], [0, "fooba"], [8, "z"]] | foobarbaz
[[0, "fo"], [0, "fooba"], [0, "foobarbaz"]] | foobarbaz
Is there any restrictions on what characters the string will contain? – GamrCorps – 2016-02-22T18:01:58.790
@GamrCorps Nope, no special restrictions. – Doorknob – 2016-02-22T18:06:13.860
1Are there any restrictions on the length of the output string? – Mego – 2016-02-22T18:43:43.900
@Mego None aside from natural limits imposed by memory/storage. – Doorknob – 2016-02-22T19:58:53.047
1HA! This is the undo mechanism in my text editor :D – slebetman – 2016-02-23T02:45:00.213
Can there be trailing spaces in the slices? – Adám – 2016-02-29T13:00:12.853
@Nᴮᶻ Solutions should be able to support slices containing any printable ASCII characters. – Doorknob – 2016-02-29T13:25:35.503