Notifications
Clear all
[Closed] array name duplicates
Feb 25, 2015 4:55 pm
Afternoon,
I have an array: obj_aray=#(“undefined”, “undefined”, “test”, “undefined”, “test”)
The outcome i want is: #(“undefined_1”, “undefined_2”, “test_1”, “undefined_3”, “test_2”)
Currently i am working with whats below. But annoyingly can’t get the above result. Help would be greatly appreciated.
test=#()
fn function_duplicate_name obj_aray =
(
uniques = #()
for x in obj_aray do (appendifunique uniques x)
for xx in 1 to uniques.count do
(
for x in 1 to obj_aray.count where (o=finditem obj_aray uniques[xx]) != 0 do
(
n=obj_aray[x]
n_rename = (obj_aray[x] + "_" + (x as string))
test[x]= n_rename
)
)
)
function_duplicate_name obj_aray
Thanks!
3 Replies
Feb 25, 2015 4:55 pm
(
obj_array = #("undefined", "undefined", "test", "undefined", "test", "something", "test", "undefined", "test" );
uniques = makeuniquearray obj_array;
for u in uniques do
(
ucount = 1;
for i = 1 to obj_array.count where obj_array[i] == u do
(
obj_array[i] = obj_array[i] + "_" + ucount as string;
ucount += 1;
)
)
obj_array;
)
Feb 25, 2015 4:55 pm
something like this may perform better if the arrays and strings get large
(
obj_array = #("undefined", "undefined", "test", "undefined", "test", "something", "test", "undefined", "test" );
hash_array = for o in obj_array collect gethashvalue o 12345679
uniques = makeuniquearray hash_array;
for u in uniques do
(
ucount = 1;
for i = 1 to hash_array.count where hash_array[i] == u do
(
obj_array[i] += ("_" + ucount as string);
ucount += 1;
)
)
obj_array;
)
slight code edit