Notifications
Clear all
[Closed] How can i invert an array of numbers?
Aug 19, 2009 3:06 pm
I mean:
I have #(1,2,3,4,5,6,7)
and i want #(7,6,5,4,3,2,1)
Some solve?
denisT: thanks for your prior answer, at last i decided to let the variables as undefined, if i need it again i can redefine it, and if not it is some garbage, but i think is not bothering too much
Maybe in some time i can look deeper into your solution, thanks for it.
3 Replies
Aug 19, 2009 3:06 pm
(
local a = #(1,2,3,4,5,6,7)
local b = for i = a.count to 1 by -1 collect a[i]
format "a == %
" a
format "b == %
" b
)
- Enrico
Aug 19, 2009 3:06 pm
This works. . .
theArray = #(1,2,3,4,5,6,7)
theNewArray = for i = theArray.count to 1 by -1 collect theArray[i]
Aug 19, 2009 3:06 pm
I like your methods, mine it’s a bit larger…i htink i don’t have as much experience as you, this is my solution, thanks!
a = #(1,2,3,4,5,6)
b = #()
for i=1 to a.count do (
i = i*-1
append b i
)
sort b
a = #()
for i=1 to b.count do (
i = b[i]
i = i*-1
append a i
)
print "invertida"
print a