Vectors in Julia
1-indexed, growable, and ! marks the mutators.
# Vectors are 1-indexed and grow in place; ! marks mutation.
queue = ["M42", "M45"]
push!(queue, "M31")
println(queue[1], " first, ", queue[end], " last")
# Slices copy; end works inside the brackets.
tail = queue[2:end]
println(tail)
pushfirst!(queue, "Moon")
sort!(queue)
println(queue)
println("Length now $(length(queue))")
How it works
push!appends in place; the bang is a naming convention.queue[end]indexes from the back; slices like[2:end]copy.sort!reorders the vector itself.
Keywords and builtins used here
end
The run, in numbers
- Lines
- 13
- Characters to type
- 329
- Tokens
- 82
- Three-star pace
- 70 tpm
At the three-star pace of 70 tokens a minute, this run takes about 70 seconds.
Step 1 of 3 in Collections, step 10 of 27 in Language basics.