A for loop without any {}

后端 未结 6 1884
借酒劲吻你
借酒劲吻你 2020-12-10 18:10

So I was reading about shuffling an array. And then I came across this script:

shuffle = function(o){ //v1.0
    for(var j, x, i = o.length; i; j = parseInt(         


        
6条回答
  •  -上瘾入骨i
    2020-12-10 18:36

    Looks like I didn't read the loop correctly.

    In this case, the evaluations are happening inside the conditions of the for loop.

    So a for loop has three parts

    for (initial variables; end cases; what to do every iteration)
    

    You define some initial stuff and use o which was passed into the function, define an end case, and then compute something every iteration. At the end, o has a new value and it gets returned.

提交回复
热议问题