Iterators: Difference between revisions
Content added Content deleted
(Created Nim solution.) |
Alpha bravo (talk | contribs) (Added AutoHotkey) |
||
Line 118: | Line 118: | ||
dc.b "Purple",0 |
dc.b "Purple",0 |
||
even</syntaxhighlight> |
even</syntaxhighlight> |
||
=={{header|AutoHotkey}}== |
|||
<syntaxhighlight lang="AutoHotkey">oDays := ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"] |
|||
oColors := ["Red","Orange","Yellow","Green","Blue","Purple"] |
|||
MsgBox % Result := "" |
|||
. "All elements:`n" Iterators(oDays) "`n" Iterators(oColors) |
|||
. "`n`nFirst, fourth, and fifth:`n" Iterators(oDays, [1,4,5]) "`n" Iterators(oColors, [1,4,5]) |
|||
. "`n`nReverse first, fourth, and fifth:`n" Iterators(oDays, [1,4,5], 1) "`n" Iterators(oColors, [1,4,5], 1) |
|||
return |
|||
Iterators(obj, num:="", rev:=0){ |
|||
for i, v in (num.Count() ? num : obj) |
|||
res .= (rev ? obj[obj.Count() +1 -v] : num.Count() ? obj[v] : v) ", " |
|||
return Trim(res, ", ") "." |
|||
}</syntaxhighlight> |
|||
{{out}} |
|||
<pre>All elements: |
|||
Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday. |
|||
Red, Orange, Yellow, Green, Blue, Purple. |
|||
First, fourth, and fifth: |
|||
Sunday, Wednesday, Thursday. |
|||
Red, Green, Blue. |
|||
Reverse first, fourth, and fifth: |
|||
Saturday, Wednesday, Tuesday. |
|||
Purple, Yellow, Orange.</pre> |
|||
=={{header|BASIC256}}== |
=={{header|BASIC256}}== |