eloquent javascript correlation tableFor explanation

前端 未结 4 898
余生分开走
余生分开走 2021-01-03 16:27

I am taking my first steps in programming and i am stuck with this problem from eloquent, in particular with the weresquirrel problem. Here it goes :

functi         


        
4条回答
  •  渐次进展
    2021-01-03 17:11

    I was also confused with the following:

    if (entry.events.includes(event)) index += 1;
    
    if (entry.squirrel) index += 2;
    
    table[index] += 1;
    

    This actually means: if (entry.events.includes(event)) index += 1; === true, add 1 to index. In that case, we can translate it as table[1] += 1

    And if below is true as well,

    if (entry.squirrel) index += 2;
    

    then: table[3] += 1

    table[3]is populated only if squirrel and entry=== true

    if (entry.squirrel) index += 2is increased by 2 because squirrelis true in table[2].

    table[index] is actually just an index we want to use as a target.

提交回复
热议问题