Array concatenation: Difference between revisions
Content added Content deleted
m (fixed Task header.) |
|||
Line 2,207: | Line 2,207: | ||
} |
} |
||
</lang> |
</lang> |
||
=={{header|S-lang}}== |
|||
<lang S-lang>variable a = [1, 2, 3]; |
|||
variable b = [4, 5, 6];</lang> |
|||
a+b is perfectly valid in S-Lang, but instead of the problem's desired |
|||
effect, it gives you a new array with each cooresponding element from |
|||
a and b added. Instead: |
|||
<lang S-lang>variable la = length(a), c = _typeof(a)[la+length(b)]; |
|||
c[ [:la-1] ] = a; |
|||
c[ [la:] ] = b;</lang> |
|||
If you can make do with using lists not arrays for a and b, it's trivial: |
|||
<lang S-lang>a = {1, 2, 3}; |
|||
b = {4, 5, 6}; |
|||
variable c = list_concat(a, b);</lang> |
|||
behaves as in the array concatination above. Then, if you need an array: |
|||
<lang S-lang>c = list_to_array(c);</lang> |
|||
As an alternative: |
|||
<lang S-lang>list_join(a, b);</lang> |
|||
adds the elements of b onto a. |
|||
=={{header|Scala}}== |
=={{header|Scala}}== |