is there already something like this?
function insert!(a::Array{T,1}, i::Integer, item::Array{T,1})
_growat!(a, i, length(item))
bd = i + length(item) - 1
@inbounds for _i in i:bd a[_i] = item[_i-i+1] end
return a
end
is there already something like this?
function insert!(a::Array{T,1}, i::Integer, item::Array{T,1})
_growat!(a, i, length(item))
bd = i + length(item) - 1
@inbounds for _i in i:bd a[_i] = item[_i-i+1] end
return a
end
Maybe splice!
?
splice!(a::Vector, index::Integer, [replacement]) -> item
…
To insertreplacement
before an indexn
without removing any items, usesplice!(collection, n:n-1, replacement)
.
oh thank you!
i had not seen this one hehe, started with Julia yesterday
@oxinabox, sorry but do not fully understand how to properly use splice!()
to insert one array into another.
It doesn’t seem right to have to loop and adjust the indices after each insertion. A simple (perhaps too simple) example of inserting Y
into X
:
X = [11, 13, 15, 17]
Y = [12, 14, 16]
ix = [2, 3, 4]
k = 0
for (i,y) in zip(ix, Y)
splice!(X, i+k:i+k-1, y)
k += 1
end
julia> X
7-element Vector{Int64}:
11
12
13
14
15
16
17