From the selected answer in this SO-question this very ingenious function creates an Array with a range from 1 to i:
function range1(i){return i?range1(i-1).concat(i):[]}
It works perfect. Call me stupid, but I just can't get my head around how it works. Let's say we have range1(5)
. Now entering the function, we have i
, so it returns itself with parameter i-1
(4) and concats i
(5) to it. But here I'm stuck: how does range1
know it has to do with an Array? I'd say after the first run the return value (as long as we have i
, so i!==0
) would be a Number. And Number has no concat
method. Can someone explain this? What am I missing?