Notifications
Clear all
[Closed] Offset array numbers
Oct 15, 2010 10:57 pm
Hey guys,
I have an array with some objects in it:
I’d like to offset the numbers automatically (without having to rename them manually), for example:
myArray[1]
myArray[2]
myArray[3]
to
myArray[4]
myArray[5]
myArray[6]
Thanks
Nahuel
3 Replies
Oct 15, 2010 10:57 pm
I think insertItem is the way to go. Just add 3 entries on myArray on position one to shift the original values.
-Johan
Oct 15, 2010 10:57 pm
What about this?
fn shiftItems arr shift item: =
(
local shiftArr = #()
case item of
(
#number: shiftArr = #{1..shift} as array
--add whatever you would like the function to insert here
default: shiftArr[shift] = undefined
)
(shiftArr + arr) --returns new array
)
Usage:
newArray = shiftItems oldArray 3
or
newArray = shiftItems oldArray 3 item:#number –in case you want to insert numbers (or something else, you get the point)