Recursive functions are your friend:
a = ['value0', 'value1', 'value2']; r = function(a, h, n){ top = a.head(); newhash = h.put({'entry.#{n}.single':top}); a.length() > 1 => r(a.tail(), newhash, n+1) | newhash; }; out = r(a, {}, 0);
out has the value {'entry.1.single' :'value1','entry.0.single' :'value0','entry.2.single' :'value2'};
A recursive function is needed here because you are performing a structure transformation. If you want to return an array, you could use the map() method.
Also note that your base register writes recursive functions. KNS sets a recursion limit.
TelegramSam
source share