I came across this bit of code:
n = args[0] as Long
[*n..1, n].any{ println ' '*it + '*'*(n - ~n - it*2) }
It's used for printing a tree form of structure. Like this:
*
***
*****
*******
*
(for n
=4)
How does the code
[*n..1,n]
produce[4, 3, 2, 1, 4]
?How does
any
method works here? The Doc doesn't help me much. What is a predictive that can be passed toany
(as mentioned in Doc's)?
Whats the use of any
and how its handled in this case?
any
wrong in this question ;) ? – Baeza