本文主要跟大家分享一個關於javascript二維陣列的面試題,希望能幫助大家。給定一個二維數組,實現一個功能函數fn,向這個函數中傳遞這個二維數組的一個坐標,如果這個坐標的值為”1“,將返回和這個坐標所有相連的並且坐標值為1坐標。
例如,傳遞了fn([3,4])所得到的結果為:
[[3,4],[4,4],[5,4],[6,4] ,[7,4],[8,4],[8,5],[8,6]]
var arr =[ [0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,1,0,0,0,1,0,0], [0,0,0,0,1,0,0,0,1,0,0], [0,0,0,0,1,0,0,0,1,0,0], [0,0,0,0,1,0,0,0,0,0,0], [0,0,0,0,1,0,0,0,0,0,0], [0,0,0,0,1,1,1,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0], ] ;
登入後複製