2014-09-22 12 views

Odpowiedz

6

W maszynopisie byś instancji 2x6 Matrix/tablicy wielowymiarowej używając następującej składni:

var matrix: number[][] = 
[ 
    [ -1, 1, 2, -2, -3, 0 ], 
    [ 0.1, 0.5, 0, 0, 0, 0 ] 
]; 

//OR 

var matrix: Array<number>[] = 
[ 
    [ -1, 1, 2, -2, -3, 0 ], 
    [ 0.1, 0.5, 0, 0, 0, 0 ] 
]; 

Równowartość w JavaScript byłoby:

var matrix = 
[ 
    [ -1, 1, 2, -2, -3, 0 ], 
    [ 0.1, 0.5, 0, 0, 0, 0 ] 
]; 

Składnia JavaScript jest również ważna w maszynopisie, ponieważ typy są opcjonalne, ale składnia TypeScript nie jest poprawna w JavaScript.

Aby uzyskać różne długości należy użyć tej samej składni w JS i TS:

var matrixLength = matrix.length; // There are two dimensions, so the length is 2. This is also the column size. 
var firstDimensionLength = matrix[0].length; // The first dimension row has 6 elements, so the length is 6 
var secondDimensionLength = matrix[1].length; // The second dimension row has 6 elements so the length is 6 
+3

zamiast 'Array []' 'polecam numer [] []' – basarat

+0

dobrym przypomnieniem. Dodałem to do opisu. Dzięki. –

Powiązane problemy